Repository navigation
Conversation
Add an opt-in block converter for <pre>. It covers Markdown fences, indented code and HTML <pre>, and produces codeBlock blocks of @plonegovbr/volto-code-block. The language comes from a language-* or lang-* class on the <code> or the <pre>; shell, sh and console map to bash, and py maps to python. Without a language, the block uses text. The option is off by default, because the codeBlock type comes from an add-on. Enable it with code_block in volto_blocks() or with --code-block in the convert command. While it is off, the <pre> block converter is hidden during the conversion, so the output stays unchanged. Closes #47
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.
Adds an opt-in block converter for
<pre>. Three inputs reach the HTML step as<pre>: Markdown fences, indented code (<pre><code>without a class) and HTML<pre>. Each becomes acodeBlockblock of@plonegovbr/volto-code-block.Setting.
volto_blocks(),html_to_blocks()andmarkdown_to_blocks()takecode_block. Pass a dict to enable the conversion. Its keysstyle,wrapLongLinesandshowLineNumbersoverride the defaults (dark,True,False). An empty dict enables it with the defaults. Theconvertcommand takes--code-block, plus--code-style,--wrap-long-lines/--no-wrap-long-linesand--show-line-numbers/--no-show-line-numbers, which require--code-block. The HTTP service is unchanged.Language. Read from a
language-*orlang-*class on the<code>or the<pre>, lowercased.shell,shandconsolemap tobash, andpytopython. Without a language the block getstext. The code is the element text without one trailing newline.Why opt-in.
codeBlockcomes from an add-on, not Volto core, so sites without it would get blocks they cannot render. With the option off, the<pre>converter is hidden during the conversion. This is needed, not just a default: registering a block converter for<pre>changes how the parser splits paragraphs and unwraps containers, so the default layout is pinned in tests for<pre>inside paragraphs, divs and sections.Open questions
POST /voltoandPOST /markdowntake the option now, or wait for a consumer?textthe right fallback for a plain<pre>, or should it beplaintext?js,ts,yml,html)?Closes #47