Skip to content

Allow custom language magics #1491

@steovd

Description

@steovd

Use case

I want my markdown docs to be executable as notebooks. The majority of code in my docs is in Python, with a few code blocks in other languages. Jupytext converts most of those languages to code cells with magics, which is great. Some languages aren't covered by built-in magics, so I wrote my own, but I can't get Jupytext to use them. Instead, it leaves those code blocks as markdown.

md:markdown ipynb cell type
Code blocks in languages with built-in magic support are converted to code cells, as they should.
```javascript
alert();
```
%%javascript
alert();
code
Code blocks in languages without built-in magic support are shown as markdown cells. Probably so they don't cause errors.
```jsx
const Hello = () => (<b>Hello</b>);
```
```jsx
const Hello = () => (<b>Hello</b>);
```
markdown
However, I wrote custom magics that can run those languages. So I want Jupytext to produce this:
```jsx
const Hello = () => (<b>Hello</b>);
```
%%jsx
const Hello = () => (<b>Hello</b>);
code

NOTE: When converting from ipynb to md:markdown, it does work like this. But not the other way around.

Possible solution

Add custom_language_magics option (or something) that will extend _JUPYTER_LANGUAGES. A list of magics would be enough for my use case, but if it mapped magics to languages, you could also use it to decide whether to comment cells out in percent formats.

Related issues

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions