Repository navigation
Fix Mermaid and line numbers on full load, number the editor lines - #42
Merged
Merged
Conversation
Mermaid block: with startOnLoad, Mermaid also treated the block wrapper, which has the mermaid class, as a diagram on a full load. It replaced the wrapper with a syntax error, and the caption went with it. The block already calls mermaid.render itself, so startOnLoad is now false. Code block: prismjs and prism-core were two instances, and each scheduled its own highlightAll when the page loaded. Before hydration, that run changed the markup and caused React hydration errors. After the blocks were highlighted, the prism-core run, which has no plugins, replaced the content of the code element and removed the line numbers, so they went missing intermittently. helpers/prism.ts is now the only instance, and helpers/prismManual.ts sets Prism to manual mode before it loads. Edit view: the line numbers are now shown there too. A marker added to each line of the highlighted code is numbered with the same CSS counter as the view, so multi-line tokens and wrapped lines need no measuring. The markers follow the Show Line Numbers and Starting Line Number settings. Tokens are static in the editor, because the dark theme positions them, which took markers inside a token out of the gutter. Closes #40 Closes #41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes two bugs seen on a full page load in 4.0.0, and adds line numbers to the Code block's edit view.
Mermaid (#40)
startOnLoad: truemade Mermaid treat the block wrapper, which has themermaidclass, as a diagram. The block already callsmermaid.render, so it is nowfalse.Line numbers (#41)
The numbers were not always missing, as the issue says: on plone.org.br they usually rendered, but went missing on some loads.
prismjsandprism-corewere two instances, and each scheduled its ownhighlightAllat load, throughrequestAnimationFrame:prism-corerun, which has no plugins, removed the numbers. A tab loading in the background makes this order likely, since it delaysrequestAnimationFrame, though that specific case is an inference.helpers/prism.tsis now the only instance, in manual mode. Importingprismjsdirectly would bring the second instance back. Prism no longer highlights the page on its own at load, which a project could only have relied on by accident.Edit view
Prism's plugin needs a
<code>element and thecompletehook, and the editor has neither. Instead, a marker on each line is numbered by the same CSS counter, so multi-line tokens and wrapped lines need no measuring. The Mermaid block has no line number settings, so it is unchanged.Tests
The acceptance tests force the failing order: a pending image holds back
load, and a delayedrequestAnimationFrameputs Prism's run after hydration. They failed onmain's source and pass here. Locally, the code block test fails on the hydration errors only; the removed numbers are covered by a unit test.Closes #40
Closes #41