Add custom_language_magics option to support user-defined language magics in Markdown notebooks#1492
Add custom_language_magics option to support user-defined language magics in Markdown notebooks#1492
custom_language_magics option to support user-defined language magics in Markdown notebooks#1492Conversation
Co-authored-by: mwouts <29915202+mwouts@users.noreply.github.com>
custom_language_magics option to support user-defined language magics in Markdown notebooks
I didn't check the code, but this doesn't sound safe. You can't assume that every custom cell magic marks a language (e.g. the built-in |
|
Hi @steovd , I take good note of this. I did ask for that feature, though, as I prefer that documents round trip well without having to fine tune the configuration (no sure how timeit does in that respect! Will be interesting to check) I had not time to check the PR either, will do on the next iteration, likely next week end. Kind regards |
|
You're right. Default behavior doesn't have to work everywhere, as long as it can be configured when needed. Maybe auto-detect new languages when Here's a practical same-language custom cell magic: More examples of non-language custom cell magics: |
Markdown code blocks in languages not covered by Jupytext's built-in
_JUPYTER_LANGUAGESset were silently kept as markdown cells instead of being converted to code cells with the appropriate%%langmagic. Users with custom magics (e.g.%%jsx) had no way to opt in.Changes
config.py: Newcustom_language_magics = List(Unicode())trait onJupytextConfiguration; propagated to format options viaset_default_format_options()formats.py: Addedcustom_language_magicsto_VALID_FORMAT_OPTIONScell_reader.py(MarkdownCellReader):__init__: Extendsstart_code_reregex to include custom languages (+ uppercase variants)options_to_metadata: Correctly extracts language name for custom languages (bypassestext_to_metadata's built-in language check which would treat unknown names as metadata keys)find_cell_end: Custom language fenced blocks now correctly act as code cell boundariesjupytext.py:reads(): Mergescustom_language_magicsinto the effective magic list passed toset_main_and_cell_language(), so cells receive their%%langprefixwrites(): Auto-detects non-standard%%langmagics in code cells and records them incustom_language_magicsnotebook metadata — enables correct round-trips without manual configurationcell_to_text.py:BaseCellExporterpassescustom_language_magicstocell_language()so%%langlines are recognized as language markers during exportdocs/advanced-options.md: New "Custom language magics" sectionUsage