-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown syntax for roles and directives #63
Comments
A suggestion from John Macfarlane: Sincewe've been talking about dedicated syntax that would map on to a directive, but wouldn't be confusable with code blocks, use what RMarkdown and Pandoc do and use
We could assume that any code blocks that had curly brackets were block-level directives, and reference the first element in the This would also be fairly parsable in other markdown parsers, since the
|
also - just a note for @rowanc1 here, I feel like if we end up using Sphinx and have a directive / role syntax for markdown, then maybe that's a place where components.ink pieces could be inserted into content at build time by writing a role/directive that injects the proper JS and HTML into the page (maybe as a separate sphinx extension?) curious what you think about that... |
My interpretation of how this would apply is:
I am putting the A couple of questions:
For example: indentation
For example: html
And that would either be ignored in other representations - or perhaps if you have an intermediate AST then it could last until there? I liked the comment you posted about the C markdown parser coming to a common xml representation that can be acted upon. |
Behold the first Markdown directive parser! See the bottom of https://github.com/chrisjsewell/mistletoe/blob/myst/test.ipynb Current format is: ````{note}
abcd *abc* [a](link)
```{warning}
xyz
```
```` which is transformed to docutils AST: <document source="">
<note>
<paragraph>
abcd
<emphasis>
abc
<pending_xref refdomain="True" refexplicit="True" reftarget="link" reftype="any" refwarn="True">
<reference refuri="link">
a
<warning>
<paragraph>
xyz FYI for all the tests (which are extensive) see: https://travis-ci.org/chrisjsewell/mistletoe |
This looks totally awesome! A quick question: should it be possible to configure default directive/role akin to sphinx? These could use blank |
Very cool. I see you're picking up line numbers corresponding to cells in the AST. So ticking all the boxes already in terms of what was needed... |
So I've added testing against most of the docutils directives (see here), and added parsing of arguments, e.g.
The last part is to parse options. It has been mentioned about parsing like I think the YAML block is the best way and I was thinking, for efficient parsing, it would be good to signify in the first line if the block contains options. Something like:
Then it would read everything as YAML until either a |
You've worked hard!!! I personally find the YAML syntax far more readable than Regarding the YAML syntax, could you do
That seems a bit more symmetric --- and hence easy to remember. |
Yeh that could also work ta. Implemented roles and math as well now (no option key/val parsing yet). It actually could end up being more powerful than RST in some respects, because you can nest inline elements, which isn't possible in RST: ````{note}
abcd *abc* [a](link)
```{warning}
xyz
```
````
```{figure}+ path/to/image
height: 40
---
Caption
```
**{code}`` a=1{`} ``**
**$a=1$**
$$b=2$$
`` a=1{`} `` goes to: <document source="">
<note>
<paragraph>
abcd
<emphasis>
abc
<pending_xref refdomain="True" refexplicit="True" reftarget="link" reftype="any" refwarn="True">
<reference refuri="link">
a
<warning>
<paragraph>
xyz
<figure>
<image height="40" uri="path/to/image">
<caption>
Caption
<paragraph>
<strong>
<literal classes="code">
a=1{`}
<paragraph>
<strong>
<math>
a=1
<paragraph>
<math_block xml:space="preserve">
b=2
<paragraph>
<literal>
a=1{`} |
@choldgraf @mmcky @jstac @AakashGfude I've added the Sphinx Parser 😃 You just install my fork of mistletoe ( Note if you look in myst/test/test_sphinx/test_sphinx_builds.py, I have set up automated testing of sphinx builds, for folders in myst/test/test_sphinx/sourcedirs. So if you run that with pytest it will actually generate the |
@choldgraf FYI front-matter does start with
|
Love your work @chrisjsewell. Outstanding. |
Duuude - it works! So cool! Tonight I'll try making a little sphinx documentation site in your myst branch using the content that @AakashGfude put together...I am curious how it'll look! |
(Chris pointed me to those discussions; I am an extensive sphinx user due to being one of the maintainers of the pandas docs, which is a quite big sphinx site. And I am excited about the issues you are tackling here: I love sphinx, but I also love to see improvements to it ;)) One thing I am wondering: to what extent are you already set on the syntax for roles and directives? It seems you are now taking the syntax for code (both for inline and blocks) with adding a role/directive name in the {}. This is closer to existing markdown syntax, so I can imagine this is easier to extend an existing parser for this? (and it's also closer to things in the existing standard / pandoc, which are very good reasons) But thinking about some usecases for roles in the documentation projects I am working with, and I think something along the lines of the generic directives syntax proposal might be easier to work with (as an end user): Small example rst snippet:
How it might look like based on the role examples above (the details might not be correct):
And how it might look like with the linked proposal:
Personally, I think the third snippet "looks" better than the second (but that's very subjective of course. Maybe that's because I am so used to having colons in rst .. ;-)) |
Yep that how it has now been implemented, as Also with colons, this might clash with the potential syntax extension of field lists . For example, if you want to be able to use the |
This is great stuff, thanks @chrisjsewell! Wondering about that yaml header: if you use two
Quickly surveying the landscape: in pandoc, the yaml blocks are surrounded by |
@stefanv I believe the main reason for this is because otherwise the regex search can become really expensive. Imagine that you have lots of code blocks with parameters inside. Because If you know there's a character that defines "this is the start of config" then it becomes much easier, so adding a starting After using it a bit, I think a way we could get around this issue is to also support some kind of arguments in the first line, and suggest that people use this only if they have a very small number of arguments. Then if the number of args is non-trivial (maybe > 2 or so) they can use the YAML, and if they number of args is small they can keep it close to a one-liner. |
Another option would be to denote that arguments section with a special character on each line. For example, "parameters can be provided by starting a line with
That would have the benefit of even more parity w/ rST. For a very short paragraph then you'd have something like:
|
Yeh as I've noted in #24, I think I will add in a block token for docutils field list syntax, which I didn't actually realise before was part of the RST spec. Then you should be able to use:
|
@chrisjsewell is the idea that this would replace the YAML parsing? Or just be an option? I quite like the YAML syntax. Instead of allowing full rST syntax could we just say that if the block starts with lines that begin with |
Yeh I don’t think I’m going to add actual parsing for these field lists any more; in favour of just using YAML. But yeh for directives you could maybe include that alternative approach. |
I think it'd be helpful to include the If there are <= 2 configuration lines:
If there are >=2 configuration lines:
Either would be valid, but for cases where the directive just needs one or two config |
Last week we had a few nice conversations around "how to extend Markdown to support roles and directives from Sphinx".
This is a quick issue to try an keep track of our thinking there.
What kinds syntax chunks are there?
What we arrived at
After a few conversations, we arrived at a syntax that uses triple-backticks, followed by directive name, followed by configuration with two options (either using
{key=val}
or YAML front-matter inside the code block).So something like (ignore the slashes, just for rendering purposes):
And for in-line text, using single-backticks followed by an identifier in the traits associated w/ it:
This effectively treats everything as "raw text", with the idea that this would degrade gracefully by just rendering as a raw blob if the directive didn't exist.
How would this clash with current markdown or rST behavior?
Something like this:
{}
becomes configuration for the directive. Anything inside the backticks becomes content that is processed by the directive.Something similar could be done with in-line blocks
What others have found
The text was updated successfully, but these errors were encountered: