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
Rendering each markdown cell causes incorrect section headers #17
Comments
Two ideas for how we could handle it:
|
You initialise a new renderer for every cell. This obviously wipes any internal state, including self._level_to_elem. |
One thing that should be checked/documented at the # Title h1
### Title h3 If think with myst, this will probably end up being the same as: # Title h1
## Title h2 I should check this, and decide how to handle it, e.g. would sphinx be happy with 'virtual' sections being added that don't have a |
Two other things:
|
Is that as straightforward as updating the attribute directly by assigning a new node? |
Yeh should be |
hmmm, I just tried doing: # Before looping cells
renderer = SphinxRenderer(document=document, current_node=None) and in the cell loop: # also tried assigning directly
renderer.set_current_node(cell_input) And I got this error: Exception occurred:
File "/c/Users/chold/Dropbox/github/forks/python/ebp/myst_parser/myst_parser/docutils_renderer.py", line 142, in render_paragraph
para.line = token.range[0]
AttributeError: 'Paragraph' object has no attribute 'range' |
Oh no you don't have to use Just literally do |
I did that, got the same error :-/ I'm doing: # If a markdown cell, simply call the Myst parser and append children
if cell["cell_type"] == "markdown":
# Initialize the render so that it'll append things to our current cell
renderer.current_node = cell_input
with renderer:
# TODO: This shouldn't be `Document` because it'll look for yaml frontmatter
# Should be something else but need to see how myst parser does it.
myst_ast = Document(cell["source"])
renderer.render(myst_ast) |
Ah yeh, you need to use the |
ahhh that got it |
I just discovered a bug (from a user's perspective) that is technically a feature in rST :-P
I just noticed that the top-level markdown header of each cell in the notebook is being treated as an H1 header for the whole document, even if the header text is technically
##
.e.g. see how Sphinx thinks there are multiple page titles for the single notebook document that is here: https://sphinx-jupyter-notebook.readthedocs.io/en/latest/
I think this is because of Sphinx deciding on page titles etc based on the order in which headers happen, so if we parse a cell with only a single
##
header, Sphinx will treat that as a document-level header.e.g., note how the Sphinx document output is the same whether the two headers have different numbers of
#
symbols.So from a docutils perspective, we need to make sure that cells that are sub-sections are nested properly. Even though notebooks have a single top-level hierarchy, docutils doesn't.
@chrisjsewell does that sound correct to you? Any ideas on the right way to do this?
The text was updated successfully, but these errors were encountered: