notebook markdown rendering improvements #10958
Open
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.
Addresses #10291
This updates some of the markdown rendering styles to better match up with the styles used in other notebooks.
What did get fixed:
What did not get fixed:
Code Blocks Whitespace Fix
Understanding the cause of the extra whitespace at the bottom of code blocks in Positron notebooks was kind of a pain. I'm including an explanation in case someone has a better suggestion. My fix included modifying the code block renderer in
markdownRenderer.tsbut I don't know why the newline was added in the first place, so maybe there's a better solution?The root cause of the extra whitespace at the bottom of code blocks in Positron notebooks is caused by:
markdownRenderer.ts:111adding a trailing\nto code blocks when rendering them to HTMLrenderHtml.tsx:75which wraps ALL text nodes (including newlines and spaces) in<span>elementsThe
renderHtmlfunction inrenderHtml.tsxlooks like it intentionally preserves all whitespace text nodes because they can be "semantically significant" but in this case the trailing\ninside the<span>is not significant and causes layout issues.Code blocks are
<code>wrapped in a<pre>. The<pre>element has built-inwhite-space: prestyle, which preserves the\ninside the<span>, causing visible whitespace at the bottom of code blocks.Built-in notebooks don't have this issue because they use
markdown-itinstead ofmarkedfor markdown rendering which doesn't add the trailing\nto code blocks from what I can tell.Table Rendering Fix
Similar to the code block styling issue with newlines; the html returned by
markdownRenderer.tsincludes newlines between all the table markup. The html looks something like:When we go to parse this html prior to rendering (
htmlParser.ts:307), we would keep all of these newlines. These newlines then got wrapped in<span>elements. Having<span>elements between the table specific elements breaks the table html spec rules.Per HTML specification:
tablecan only contain:caption,colgroup,thead,tbody,tfoot,trthead,tbody,tfootcan only contain:trtrcan only contain:td,thBreaking this spec prevented existing css from working on tables, such as
border-collapse: collapse, which prevents double borders.To fix this, we now filter out whitespace-only text nodes that are between the table elements listed above when we parse the html string.
AFTER
Untitled.mov
Release Notes
New Features
Bug Fixes
QA Notes
@:positron-notebooks
For testing, I used the following markdown: