hplgit / doconce

Lightweight markup language - document once, include anywhere
http://hplgit.github.io/doconce/doc/web/index.html
Other
309 stars 60 forks source link

ipynb2doconce crashes on Markdown fenced code blocks with language identifier #156

Closed lexnederbragt closed 6 years ago

lexnederbragt commented 6 years ago

Doconce 1.4.5

Jupyter notebook with this markdown cell:

```python tekst = "hallo, verden" ```

Command doconce ipynb2doconce notebook.ipynb crashes with

  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/site-packages/doconce/doconce.py", line 357, in <lambda>
    (r"\n?```([A-Za-z]+)(.*?)\n```", lambda m: "\n\n!bc %scod%s%s\n!ec\n" % (extended_markdown_language2dolang[m.group(1)], bc_postfix, unindent_lines(m.group(2).rstrip(), trailing_newline=False)), re.DOTALL), # language given
KeyError: 'python'

(Full Traceback below).

Workaround: remove language identifier:

``` tekst = "hallo, verden" ```

Desired solution: no need to remove language identifier 😉

Full Traceback:

Traceback (most recent call last):
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/bin/doconce", line 4, in <module>
    __import__('pkg_resources').run_script('DocOnce==1.4.5', 'doconce')
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 658, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1438, in run_script
    exec(code, namespace, namespace)
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/site-packages/DocOnce-1.4.5-py3.6.egg-info/scripts/doconce", line 1723, in <module>
    bg_session = main()
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/site-packages/DocOnce-1.4.5-py3.6.egg-info/scripts/doconce", line 1712, in main
    retval = eval(command + '()')
  File "<string>", line 1, in <module>
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/site-packages/doconce/misc.py", line 8707, in ipynb2doconce
    s = markdown2doconce(cell['source'], ipynb_mode=True)
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/site-packages/doconce/doconce.py", line 415, in markdown2doconce
    filestr = re.sub(r[0], r[1], filestr, flags=r[2])
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/re.py", line 191, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/anaconda3/envs/doconce_1_4_5_nbformat_4_3/lib/python3.6/site-packages/doconce/doconce.py", line 357, in <lambda>
    (r"\n?```([A-Za-z]+)(.*?)\n```", lambda m: "\n\n!bc %scod%s%s\n!ec\n" % (extended_markdown_language2dolang[m.group(1)], bc_postfix, unindent_lines(m.group(2).rstrip(), trailing_newline=False)), re.DOTALL), # language given
KeyError: 'python'
KGHustad commented 6 years ago

Thanks for reporting this bug. The language specifier used to be case sensitive, so that Python would work, while python would not.