jupyter-book / myst-spec

MyST is designed to create publication-quality, computational documents written entirely in Markdown.
https://mystmd.org/spec
MIT License
14 stars 6 forks source link

Add attributes syntax #37

Open chrisjsewell opened 2 years ago

chrisjsewell commented 2 years ago

Relevant links:

Attributes are a common Markdown syntax extension, e.g. {#id .class value=key}, which I think might be useful in MyST.

At a block-level, I think this would be relatively simple to implement in https://github.com/executablebooks/MyST-Parser, since they would essentially follow the same rules/logic as targets, e.g.

(target)=
# header

would be equivalent to

{#target}
# header

But then extra logic could also be added, to propagate classes as well as identifiers (for now we would ignore key/values), e.g.

{#target .class1 .class2}
# header

Would relate to HTML like

<h1 id="target" class="class1 class2">header</h1>

another place they could be added, is for defining role options, e.g. {name}`content`{#id .class key=value}

The problem here, though, is that docutils roles syntax does not support options. Although it is of note, that the role functions themselves, do actually accept an options key-word: https://github.com/live-clones/docutils/blob/48bb76093b4ba83654b2f2c86e7c52c4bb39c63b/docutils/docutils/parsers/rst/roles.py#L197-L211

chrisjsewell commented 2 years ago

One thing I'd note here, is that pandoc have their header attributes inline with the heading text, rather than above it:

# header {#target}

But actually this is contrary to the Markdown creator's proposal

Allow attributes to be added on the line before any block element and directly after any inline element

which I think makes a lot more sense

rowanc1 commented 1 year ago

Another pointer to some users asking questions about this: