Skip to content

Commit e060de8

Browse files
feat: change markdown standard to GFM
Change markdown standard to Github Flavored Markdown (GFM) replacing Pandoc's default markdown. This is consistent with the Jupyter Notebook markdown cells and should improve compatibility.
1 parent f7647f2 commit e060de8

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

doc/markdown-cells.ipynb

+38-7
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,47 @@
2323
"* Green\n",
2424
"* Blue\n",
2525
"\n",
26-
"Note: JupyterLab and JupyterNotebook uses a different Markdown parser than nbsphinx (which currently uses Pandoc). \n",
27-
"In case that your Bulletpoints do render in the notebook and do not render with nbsphinx, please add one blank line before the bulletpoints.\n",
28-
"***\n",
26+
"JupyterLab and JupyterNotebook use a different Markdown parser than nbsphinx\n",
27+
"(which currently uses Pandoc). When using Pandoc v2.0 or later, nbsphinx uses\n",
28+
"GitHub-flavored markdown, this is the same standard of markdown used by\n",
29+
"JupyterLab and JupyterNotebook.\n",
2930
"\n",
31+
"In particular, newer versions of nbsphinx (>v0.9.5) will now correctly convert\n",
32+
"lists without a blank line:\n",
33+
"\n",
34+
"```markdown\n",
35+
"No new line before this list:\n",
36+
"1. One\n",
37+
"2. Two\n",
38+
"3. Three\n",
39+
"```\n",
40+
"No new line before this list:\n",
3041
"1. One\n",
31-
"1. Two\n",
32-
"1. Three\n",
42+
"2. Two\n",
43+
"3. Three\n",
44+
"\n",
45+
"\n",
46+
"Arbitrary Unicode characters should be supported, e.g. łßō. Note, however, that\n",
47+
"this only works if your HTML browser and your LaTeX processor provide the\n",
48+
"appropriate fonts."
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"metadata": {},
54+
"source": [
55+
"## Task Lists\n",
3356
"\n",
34-
"Arbitrary Unicode characters should be supported, e.g. łßō.\n",
35-
"Note, however, that this only works if your HTML browser and your LaTeX processor provide the appropriate fonts."
57+
"nbsphinx supports GitHub-style task lists:\n",
58+
"\n",
59+
"```\n",
60+
"- [x] Task 1\n",
61+
"- [ ] Task 2\n",
62+
"- [ ] Task 3\n",
63+
"```\n",
64+
"- [x] Task 1\n",
65+
"- [ ] Task 2\n",
66+
"- [ ] Task 3"
3667
]
3768
},
3869
{

src/nbsphinx/__init__.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -1039,13 +1039,22 @@ def filter_func(text):
10391039
json_data = json.loads(text, object_hook=object_hook)
10401040
return json.dumps(json_data)
10411041

1042-
input_format = 'markdown'
1043-
input_format += '-implicit_figures'
10441042
v = nbconvert.utils.pandoc.get_pandoc_version()
1045-
if nbconvert.utils.version.check_version(v, '1.13'):
1046-
input_format += '-native_divs+raw_html'
10471043
if nbconvert.utils.version.check_version(v, '2.0'):
1048-
input_format += '-smart' # Smart quotes etc. are handled by Sphinx
1044+
"""Accodring to https://nbformat.readthedocs.io/en/latest/format_description.html#markdown-cells
1045+
the kind of markdown used by jupyter is github flavored markdown (gfm).
1046+
1047+
The gfm extension was added in 2.0
1048+
(https://pandoc.org/releases.html#pandoc-2.0-2017-10-29).
1049+
"""
1050+
input_format = 'gfm-smart'
1051+
else:
1052+
input_format = 'markdown'
1053+
input_format += '-implicit_figures'
1054+
if nbconvert.utils.version.check_version(v, '1.13'):
1055+
input_format += '-native_divs+raw_html'
1056+
if nbconvert.utils.version.check_version(v, '2.0'):
1057+
input_format += '-smart' # Smart quotes etc. are handled by Sphinx
10491058

10501059
rststring = pandoc(text, input_format, 'rst', filter_func=filter_func)
10511060
rststring = re.sub(

0 commit comments

Comments
 (0)