-
Notifications
You must be signed in to change notification settings - Fork 197
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
Add support for rendering admonitions using "markdown friendly" syntax #154
Comments
I suppose this could be an extension that others can activate out of the box, but I'm a little hesitant to include this in default behavior. It'll mean we have two ways of doing the exact same thing (" What's the reason why we would recommend people use this syntax over I think one way to keep this clean is to create a different package that is a plugin for this one, and have a system that allows you to activate these plugins in a way that the myst-parser knows how to use. That way people could include other markdown extensions as well. |
I'd like to chip in here. My main problem with admonitions as they are now is not so much their syntax, but rather what they offer in sphinx out of the box. Specifically, the specialized ones (warning/error/note) offer a pre-defined style, but do not allow to tweak the title. Further none of them are be collapsible. I have used the One of the items on my todo list in converting my mkdocs list to jupyter-book is to override all sphinx admonitions, and cook something together using sphinx-panels instead. Perhaps this is also something to consider more generally. |
re: admonitions, we actually implemented the following option in the pydata-sphinx-theme (and thus in jupyter book)
see the last example here: https://pydata-sphinx-theme.readthedocs.io/en/latest/demo/demo.html#admonitions it's not documented because I'm not sure if it's a good idea or not haha, do you think it's a good idea? |
Don't know if it's a good idea, but I'll 100% use it. Now if only they also had a collapsible version that rendered like the dropdown from sphinx-panels... |
Well yeh that "option" (I'd more just say that you fixed the CSS 😛 ) is also available with the RTD theme. Anyway that's the approach I used in this page, plus adding custom icons and funky sphinx panels stuff: https://aiida.readthedocs.io/projects/aiida-core/en/latest/intro/get_started.html |
@chrisjsewell lol that's a good point, we actually changed this behavior to be more generic and now I realized that it's generic enough that is no longer pydata-sphinx-theme-specific haha |
well I guess that's just a matter of playing around some more with the CSS 😄 anyway, for the admonitions: the point was:
As we've discussed previously, to placate the people that want myst to be rendered by Jupyter better "out-of the-box", i.e. :::note
Here *nested* syntax will **render** within a general markdown viewer.
::: :::note ```note
Here it *is* just **shown** as is
```
We already have that; its called markdown-it-py! |
makes sense 👍 do we see any reason that we'd want these two syntaxes to behave differently?
so then the plugin would be defined inside |
Yep the same way that #132 and #153 will be optionally activated, by making this more configurable: MyST-Parser/myst_parser/main.py Lines 31 to 45 in 8dda2f7
|
Another quick thought here as I was playing around with writing this kind of syntax. If we support
equivalent to
since we are not over-riding any other behavior with it. I think other than that difference, the two patterns should behave exactly the same way. E.g. you could do
and
The one downside I can see there is that there isn't an obvious separation between the directive name and its arguments |
Question about the "notes require no inputs, so they can be on the same line". For example:
This seems a bit different than commonmark, which would ignore the paragraph (and not show up in most MD renderers). For example, in github that is rendered as a blank box :(:
Also, it seems more like the title "defaults" to Note, and perhaps you should be able to override it? For example:
I am currently playing with the implementation using |
Unsure about how best to have admonitions on a single line. See: executablebooks/MyST-Parser#154
you are describing things that I wish existed in Sphinx but they don't :-) This is a really annoying quirk of reStructuredText / docutils - basically, the argument just after the directive name could be parsed as an argument. But, if that directive doesn't accept arguments, then the text in that location will instead be parsed as content for the directive. So that's what you can do:
and you can also do
|
Could we not bypass that for the markdown parser to make it more sensible and more in line with commonmark (which ignores the first line as "info")? There could be post processing on the syntax coming out of the markdown parser that changes "notes with a title" to "admonition with a class and a title". This could be done before passing off to sphinx, perhaps? |
Yes for general directives this is a logical convention "imposed" by docutils and required by some extensions (e.g. sphinx tabs). As @choldgraf mentioned, to create adminitions with specific heading, you would use:
note here I add one or more classes: most HTML themes use the class, identical to the name of the admonition, to format the admonition box, via css (or you can always add custom css). So this would look the same as the warning directive, but with a different title. As mentioned previously, this necessitates the ability for the syntax to capture additional data to the directive type and title.
This is simple and would work for all admonitions. However, the down-side is that it would not generalise to e.g. figures where you need to capture more than just the |
i.e. implement an extension in markdown-it-py to encapsulate something like pandoc fenced divs
or suggested in jupyter jupyter/notebook#1292 (comment)
Then render it here
The text was updated successfully, but these errors were encountered: