Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent heading levels with AsciiDoc output #10062

Closed
jeffmelville opened this issue Aug 6, 2024 · 3 comments
Closed

Inconsistent heading levels with AsciiDoc output #10062

jeffmelville opened this issue Aug 6, 2024 · 3 comments
Labels

Comments

@jeffmelville
Copy link

When converting fragments to AsciiDoc, heading levels are not converted consistently. It appears that the lowest level heading always gets converted to === in AsiiDoc. See example below. In both examples, I would expect ### third to convert to === third. The issue occurs when exporting with nbconvert, which executes pandoc on one Jupyter cell at a time.

Also see: jupyter/nbconvert#1456

➜  ~ pandoc --version
pandoc 3.1.9
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /Users/jmelville/.local/share/pandoc
Copyright (C) 2006-2023 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
➜  ~ echo -e '### third\n' | pandoc -t asciidoc
== third
➜  ~ echo -e '## second\n### third\n' | pandoc -t asciidoc
== second

=== third

Pandoc version?

3.1.9 on MacOS
I also re-ran on 3.3 to confirm.

@jgm
Copy link
Owner

jgm commented Aug 6, 2024

Asciidoc sections are not supposed to have gaps, e.g.

== one

==== four

If you try this you'll get a warning like

asciidoc: WARNING: my.adoc: line 3: section title out of sequence: expected level 3, got level 4

So, we normalize them before writing. This is by design.

Note: it seems that asciidoc (original) also required the first heading level to be ==, but asciidoctor does not. So we could perhaps change this behavior.

@jeffmelville
Copy link
Author

jeffmelville commented Aug 6, 2024

Ah - I guess I see how it gets that way. There aren't gaps in the test vectors per se, but since nbconvert calls pandoc individually with each cell, it's possible for each call to pandoc to not have the right context. Something like this:

Cell 1 (Markdown):

## Some section title

** Cell 2** (Code):

IPython.display.display_image(image_bytes)

Cell 3 (Markdown)

### Subsection Title

#### Sub-subsection Title

will get converted as

== Some section title

image::image_path.png[]

== Subsection Title       # <-  This is one level too low

=== Sub-subsection Title   # <- This is also one level too low, but correctly +1 from its parent in the cell

There another issue with nbconvert and AsciiDoc output (jupyter/nbconvert#2152) but I'm working around that one within nbconvert.

Its hard for me to figure out how to correctly use pandoc AsciiDoc output with Markdown fragments given the current behavior. If I export the whole notebook as Markdown first, I can use pandoc to convert that to AsciiDoc but I lose some other information.

@jgm
Copy link
Owner

jgm commented Aug 7, 2024

Due to changes in makeSections, pandoc no longer ensures "gaplessness" in the sections anyway. Since asciidoc has changed in caring about the bottom level, I'm just going to remove that feature and have it use whatever level was in the original...

@jgm jgm closed this as completed in 1f093ea Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants