Skip to content

Fix markdown2asciidoc function for pandoc >= 3.0 (closes #2017) #2152

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

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,7 @@ raw template
{%- endblock in_prompt -%}
"""


exporter_attr = AttrExporter()
output_attr, _ = exporter_attr.from_notebook_node(nb)
assert "raw template" in output_attr
Expand Down
15 changes: 14 additions & 1 deletion nbconvert/filters/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

import re

from packaging.version import Version

from nbconvert.utils.pandoc import get_pandoc_version

try:
from .markdown_mistune import markdown2html_mistune

Expand Down Expand Up @@ -66,7 +70,16 @@ def markdown2html_pandoc(source, extra_args=None):

def markdown2asciidoc(source, extra_args=None):
"""Convert a markdown string to asciidoc via pandoc"""
extra_args = extra_args or ["--atx-headers"]

# Prior to version 3.0, pandoc supported the --atx-headers flag.
# For later versions, we must instead pass --markdown-headings=atx.
# See https://pandoc.org/releases.html#pandoc-3.0-2023-01-18
atx_args = ["--atx-headers"]
pandoc_version = get_pandoc_version()
if pandoc_version and Version(pandoc_version) >= Version("3.0"):
atx_args = ["--markdown-headings=atx"]

extra_args = extra_args or atx_args
asciidoc = convert_pandoc(source, "markdown", "asciidoc", extra_args=extra_args)
# workaround for https://github.com/jgm/pandoc/issues/3068
if "__" in asciidoc:
Expand Down
4 changes: 4 additions & 0 deletions tests/exporters/test_asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def test_export(self):
assert re.findall(in_regex, output)
assert re.findall(out_regex, output)

# Assert that the Markdown header from our test notebook made it into the output.
# This can fail when nbconvert invokes pandoc incorrectly, as in issue #2017.
assert "== NumPy and Matplotlib examples" in output

@onlyif_cmds_exist("pandoc")
def test_export_no_prompt(self):
"""
Expand Down
Loading