question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Standardizing how to add cell metadata between code and markdown cells

See original GitHub issue

Something I’ve noticed adds some (I think unnecessary) cognitive burden re: cell tags.

Currently there are two different syntaxes for cell metadata.

  • If the cell is a code cell, you provide metadata like so (ignore the backslashes):

    \```python tags=["tag1", "tag2"]
    code
    \```
    
  • If the cell is a “region” (aka markdown cell), you provide it like this:

    <!-- #region {"tags": ["tag1", "tag2"]} -->
    sometext
    <!-- #endregion -->
    
    

I find myself often using the first style in markdown cells, e.g. doing:

<!-- #region tags=["tag1", "tag2"]} -->
sometext
<!-- #endregion -->

This then gets read in as a “title” metadata instead of cell tags.

I feel like this is an unnecessary difference in syntax, at least from a user’s perspective. Is there a strong technical reason that it needs to be different between the two?

(a related point, it’d be nice to relax some of the strong JSON requirements for that metadata. for those who are writing it directly into markdown files, it’s annoying to have to remember to, e.g., use double-quotes only instead of single quotes etc.)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
mwoutscommented, Oct 18, 2019

Sure!

Well, not exactly: the cell_metadata_json option is just the format in which the metadata will be written by Jupytext. Whatever the value of the option it will be able to read metadata in either form, key/value or JSON. Only when it writes the notebook back to text, Jupytext will apply that option. Again, the aim here is to minimize the impact of format changes on the existing text notebooks.

1reaction
choldgrafcommented, Oct 18, 2019

I quite like it! It works fine for me, I tried a few combinations of varying objects etc and wasn’t able to “break” things 😃

That said - one strange behavior I noticed was that if you write python code directly into the values, it’ll get executed. e.g., if I write

<!-- #md meta=2+2} -->
test 1
<!-- #endmd -->

Then the output will be “4”. That seems vaguely insecure to me, no?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code and Markdown Cells in Jupyter Notebook - Earth Lab
Create new cell, Esc + a (above), Esc + b (below), Insert→ Insert Cell Above OR Insert → Insert Cell Below ; Copy...
Read more >
Markdown Cells — Jupyter Notebook 6.5.2 documentation
Markdown Cells . Text can be added to Jupyter Notebooks using Markdown cells. You can change the cell type to Markdown by using...
Read more >
Notebook Cell-Type Generalisation - Jupyter Community Forum
Whilst Notebooks are currently comprised of three cell types: Markdown, Code, and Raw cells; these are “implementation details”.
Read more >
Basic notebook operations | Learning Jupyter
Run All Below: Run all cells below the current cell. Cell Type: Change the type of cell selected to Code, Markdown, or Raw...
Read more >
Add metadata to your book pages - Jupyter Book
To enable the cell tag editor, click View -> Cell Toolbar -> Tags . This will enable the tags UI. Here's what the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found