From 7968f56301f6fe8448bd4b2643571faa71fde741 Mon Sep 17 00:00:00 2001 From: thomasjm Date: Fri, 31 May 2024 03:49:29 -0700 Subject: [PATCH] nbconvert: fix asciidoc markdown export (jupyter/nbconvert#2017) --- .../python-modules/nbconvert/default.nix | 5 ++- .../nbconvert/fix-asciidoc.patch | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/python-modules/nbconvert/fix-asciidoc.patch diff --git a/pkgs/development/python-modules/nbconvert/default.nix b/pkgs/development/python-modules/nbconvert/default.nix index 870b0dba108830a..e2b285ee60a6321 100644 --- a/pkgs/development/python-modules/nbconvert/default.nix +++ b/pkgs/development/python-modules/nbconvert/default.nix @@ -47,7 +47,10 @@ buildPythonPackage rec { # Add $out/share/jupyter to the list of paths that are used to search for # various exporter templates - patches = [ ./templates.patch ]; + patches = [ + ./templates.patch + ./fix-asciidoc.patch + ]; postPatch = '' substituteAllInPlace ./nbconvert/exporters/templateexporter.py diff --git a/pkgs/development/python-modules/nbconvert/fix-asciidoc.patch b/pkgs/development/python-modules/nbconvert/fix-asciidoc.patch new file mode 100644 index 000000000000000..465aa7320871924 --- /dev/null +++ b/pkgs/development/python-modules/nbconvert/fix-asciidoc.patch @@ -0,0 +1,43 @@ +From 7f4e3bbb4a523df2d1866310a09697c601277678 Mon Sep 17 00:00:00 2001 +From: thomasjm +Date: Thu, 30 May 2024 02:54:34 -0700 +Subject: [PATCH] Fix markdown2asciidoc function for pandoc >= 3.0 (closes + #2017) + +--- + nbconvert/filters/markdown.py | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/nbconvert/filters/markdown.py b/nbconvert/filters/markdown.py +index 7e4bee9fd..fe0cb10e2 100644 +--- a/nbconvert/filters/markdown.py ++++ b/nbconvert/filters/markdown.py +@@ -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 + +@@ -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: