Skip to content

Commit

Permalink
feat: change markdown standard to GFM
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tachyonicClock committed Sep 4, 2024
1 parent f7647f2 commit 4c652b6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
45 changes: 38 additions & 7 deletions doc/markdown-cells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,47 @@
"* Green\n",
"* Blue\n",
"\n",
"Note: JupyterLab and JupyterNotebook uses a different Markdown parser than nbsphinx (which currently uses Pandoc). \n",
"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",
"***\n",
"JupyterLab and JupyterNotebook use a different Markdown parser than nbsphinx\n",
"(which currently uses Pandoc). When using Pandoc v2.0 or later, nbsphinx uses\n",
"GitHub-flavored markdown, this is the same standard of markdown used by\n",
"JupyterLab and JupyterNotebook.\n",
"\n",
"In particular, newer versions of nbsphinx (>v0.9.5) will now correctly convert\n",
"lists without a blank line:\n",
"\n",
"```markdown\n",
"No new line before this list:\n",
"1. One\n",
"2. Two\n",
"3. Three\n",
"```\n",
"No new line before this list:\n",
"1. One\n",
"1. Two\n",
"1. Three\n",
"2. Two\n",
"3. Three\n",
"\n",
"\n",
"Arbitrary Unicode characters should be supported, e.g. łßō. Note, however, that\n",
"this only works if your HTML browser and your LaTeX processor provide the\n",
"appropriate fonts."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task Lists\n",
"\n",
"Arbitrary Unicode characters should be supported, e.g. łßō.\n",
"Note, however, that this only works if your HTML browser and your LaTeX processor provide the appropriate fonts."
"nbsphinx supports GitHub-style task lists:\n",
"\n",
"```\n",
"- [x] Task 1\n",
"- [ ] Task 2\n",
"- [ ] Task 3\n",
"```\n",
"- [x] Task 1\n",
"- [ ] Task 2\n",
"- [ ] Task 3"
]
},
{
Expand Down
19 changes: 14 additions & 5 deletions src/nbsphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,22 @@ def filter_func(text):
json_data = json.loads(text, object_hook=object_hook)
return json.dumps(json_data)

input_format = 'markdown'
input_format += '-implicit_figures'
v = nbconvert.utils.pandoc.get_pandoc_version()
if nbconvert.utils.version.check_version(v, '1.13'):
input_format += '-native_divs+raw_html'
if nbconvert.utils.version.check_version(v, '2.0'):
input_format += '-smart' # Smart quotes etc. are handled by Sphinx
"""Accodring to https://nbformat.readthedocs.io/en/latest/format_description.html#markdown-cells
the kind of markdown used by jupyter is github flavored markdown (gfm).
The gfm extension was added in 2.0
(https://pandoc.org/releases.html#pandoc-2.0-2017-10-29).
"""
input_format = 'gfm-smart'
else:
input_format = 'markdown'
input_format += '-implicit_figures'
if nbconvert.utils.version.check_version(v, '1.13'):
input_format += '-native_divs+raw_html'
if nbconvert.utils.version.check_version(v, '2.0'):
input_format += '-smart' # Smart quotes etc. are handled by Sphinx

rststring = pandoc(text, input_format, 'rst', filter_func=filter_func)
rststring = re.sub(
Expand Down

0 comments on commit 4c652b6

Please sign in to comment.