Skip to content

Commit

Permalink
nbconvert: fix asciidoc markdown export (jupyter/nbconvert#2017)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed May 31, 2024
1 parent 89cba26 commit 7968f56
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkgs/development/python-modules/nbconvert/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions pkgs/development/python-modules/nbconvert/fix-asciidoc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 7f4e3bbb4a523df2d1866310a09697c601277678 Mon Sep 17 00:00:00 2001
From: thomasjm <tom@codedown.io>
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:

0 comments on commit 7968f56

Please sign in to comment.