Closed MarcoGorelli closed 2 years ago
Looks like I just need to add:
read['metadata']['language_info'] = {'pygments_lexer': 'ipython3'}
Thank you @MarcoGorelli for documenting this! This is very helpful.
Reckon read
should pull that out from the .md
file and add it to the notebook metadata?
This might be more user friendly indeed. @chrisjsewell what is your opinion on this ?
Just FYI, my use-case would be to support running linters/formatters directly on jupytext .md files (https://github.com/nbQA-dev/nbQA/pull/745 )
For now I'll get around it with
# get lexer: see https://github.com/mwouts/jupytext/issues/993
parser = MarkdownIt("commonmark").disable("inline", True)
parsed = parser.parse(content)
lexer = None
for token in parsed:
if token.type == "fence" and token.info.startswith("{code-cell}"):
lexer = remove_prefix(token.info, "{code-cell}").strip()
md_content["metadata"]["language_info"] = {"pygments_lexer": lexer}
break
Example:
t.md
with the following:Then, if I open
t_new.md
, it's exactly the same ast.md
, but it has:instead of
Is there a way to round-trip a file such that it retains these directives?
Versions: