diff --git a/nbconvert/filters/markdown.py b/nbconvert/filters/markdown.py index 7e4bee9fd..f8f899b08 100644 --- a/nbconvert/filters/markdown.py +++ b/nbconvert/filters/markdown.py @@ -6,6 +6,8 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. +from nbconvert.utils.pandoc import get_pandoc_version +from packaging.version import Version import re try: @@ -66,7 +68,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: