Inline variable insertion in markdown

Is this the kind of thing that could be prototyped via an extension in nbclient? To my knowledge, that library doesn’t have an extension point that would let you execute inline markdown in the same order that it appears in a notebook (ie, I feel like there is a pretty strict separation between MD and code cells, so prototyping this would require modifying library code…I would love to be proven wrong there though!)

I think that adding in this to nbclient would mean modifying this line here and adding some logic to check for “inline execution w/ markdown syntax”:

Though, I think there’s some questions to understand there (e.g., is the original executable code now replaced with the output? is the output stored in the notebook and how it’s used is up to the renderer?)


(quick thoughts on syntax since I think that’s an interesting question)

I think @matthew.brett 's moustache+dot is a nice idea! The moustaches generally evoke the assumption that “this thing will be replaced by something else” and the . is a nice way to differentiate “executable” moustaches from regular interpolation moustaches.

Two other ideas for syntax since we are brainstorming:

Take inspiration from IPython

Piggy-back on Jupyter’s roots and use a similar syntax to the IPython kernel, the [ ]: syntax. So you could imagine:

  • The shape is []:`a.shape[0]` for default kernel
  • The shape is [python3]:`a.shape[0]` to specify a specific kernel
  • The shape is [py]:`a.shape[0]` to specify a kernel w/ shorthand

Or you could remove the : and this would then have a very similar structure to MyST Markdown directives:

  • The shape is []`a.shape[0]` for default kernel
  • The shape is [python3]`a.shape[0]` to specify a specific kernel
  • The shape is [py]`a.shape[0]` to specify a kernel w/ shorthand

Take inspiration from RMarkdown

You could use the same pattern that RMarkdown uses, but keep j for a generic execution that would use the default kernel. For a more specific kernel you could specify that instead of the j. So:

  • The shape is `j a.shape[0]` would use the kernel of the notebook in a language-agnostic way
  • The shape is `py a.shape[0]` would be a way to specify a Python kernel explicitly
1 Like