cython magic: extract style, body, not full HTML document #5760
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
displaying the full HTML document inline can result in problems rendering and can produce invalid HTML documents after export via nbconvert, mystnb, etc. In particular, my jupyter-book-built pages with
%%cython --annotateoutput end up applying.cythonto the document body because of the duplicated<body>tags, in particular causing the whole page to render with courier.This is easier and cleaner with a full HTML parser, but I imagine you don't want that as a dependency just for this. My in-production workaround is here:
but in the absence of proper HTML parsing, this regular expression splitting seems to work well enough, given how basic Cython-generated HTML is, and we just want the whole body and any style tag(s).
Another (probably better) way would be to request this subset of HTML from the annotation process, but I couldn't see a simple way to do that.