-
Notifications
You must be signed in to change notification settings - Fork 84
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
Section headings in markdown render nodes outside of the InputCell nodes #30
Comments
One option that would be fairly hacky would be to, at the end of the "render" operation, check if there are any non |
Hmm thats a tricky one. It feels like you have two immiscible hierarchies here; sections and markdown cells, since both can encapsulate each other. Do you actually need to wrap the markdown cells in |
Well, the main trick is that
This brings up a third point - since tags are the lightest-weight way to add metadata to cells, what if we adopted the
as valid, and it'll parse anything after the |
This is possible in HTML, because headers are stored in a flat structure: <div class="cell">
<h1>This is heading 1</h1>
<p>This is some text.</p>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
</div>
<div class="cell">
<h3>This is heading 3</h3>
</div> But in the doctree format (with heirarchical headers) this is surely impossible to represent <cell>
<section h1>
This is some text
<section h2>
This is some other text. How can you close the cell and start h3 here? I feel if you did want this, it would be more robust to deal with this in the HTML translator, if you had signalled the cell begin/end in the docutils tree, something like: <comment classes=["markdown_cell_start"]>
<section h1>
This is some text
<section h2>
This is some other text.
<comment classes=["markdown_cell_end"]>
<comment classes=["markdown_cell_start"]>
<section h3>
<comment classes=["markdown_cell_end"]> |
The only thing with this is that it does not allow for strict round-tripping, as opposed to:
In general though, I feel we should be emphasising the use of in-text directives or syntax, rather than markdown cell metadata. For example in your Hiding markdown cells, with MyST I feel it would be better to either comment out text you don't want in the document:
or using a directive to indicate toggle views, like you can do with the cloud sphinx theme:
|
So just to clarify, it sounds like you're suggesting we shouldn't be using container nodes at all for this, and instead using a custom html translator along with some kind of metadata that's included w comments in the sphinx AST? I guess the translator would need to override the comment render function, to check for the tag metadata and render the div blocks as needed? Maybe @mmcky could advise on the best way to do this? |
For markdown cells yes, because IMO it's theoretically impossible, given the docutils AST, to add a container that is guaranteed to not break the section hierarchy. For code cells it should be fine. The only possible edge-case I could think of is if a code output had a |
OK - I'll try adding a lightweight HTMLTranslator that overrides comment behavior...I might have some questions since I haven't build a translator before :-) |
OK quick question for @chrisjsewell: How do we handle the case when we are leaving a codecell? We want the renderer to start adding nodes as a sibling of the |
Question 2: is there any way to do this without manually setting a custom HTMLTranslator? I ask this because I know some Sphinx themes also do this, so if we want to use our own HTMLTranslator, those themes would not be able to use this functionality of MyST-NB. |
Well you want to revert to the last node that was the with self.current_node_context(node, append=True):
self.render_children(token) which reverts the current_node back to its original state on exit. |
I have no idea about |
OK, I thought about your point re: nestedness and the AST, and decided to stop being stubborn and re-work the parser so that it no longer forces the top-level "flat" cell structure that notebooks have. Check out #31 for the latest state of this...I think it's an approach that more naturally fits with the AST we're working with |
I just noticed that we have a bug in how the rendered docutils nodes are put (or not) inside of the
CellInputNode
that should contain them. I think I know what the problem is.For each markdown cell, we create a
CellInputNode
and set it as the current node. Then we render the markdown content inside. What we want is for whatever nodes are spit out to be put inside theCellInputNode
(as children). This usually works for most markdown. However, if there are section headers, or other syntax that should trigger a new section, then the render function creates a new section and starts rendering outside of theCellInputNode
. I think this is where that happens for headers:https://github.com/ExecutableBookProject/myst_parser/blob/develop/myst_parser/docutils_renderer.py#L259
@chrisjsewell can you think of a way that we can ensure the renderer is always placing objects inside the
CellinputNode
?The text was updated successfully, but these errors were encountered: