Fix Slate conversion defects from Plone → Volto migration (#31, #32, #33) - #34
Merged
Conversation
A <span> carrying text-decoration: underline (or line-through) had its formatting silently dropped during conversion. Map underline to a slate 'u' element and line-through to 's', matching the behaviour of the native <u>/<s> tags. The check uses a substring match so CSS shorthand (e.g. 'underline dotted red') is handled as well. The six style branches in _span_ are collapsed into a lookup table to keep cyclomatic complexity under ruff's C901 threshold.
A run of consecutive inline elements (e.g. two adjacent <b> tags) followed by plain text had that trailing text hoisted out of the parent paragraph and emitted as a sibling block. The cause was group_inline_nodes treating a plain text node as non-inline, which broke the inline run so its wrapper survived as a nested block. Treat plain text nodes as inline content (is_inline or is_simple_text) so they continue the run, matching the predicate already used by _group_top_level.
Deeply-nested <div> structures produced Slate that Volto cannot render:
null entries, type-less {children: [...]} nodes, <p> inside <p>, and bare
text mixed with block siblings. Source HTML full of spacers also generated
long runs of empty paragraphs.
- _div_ now flattens its assembled children (slate.flatten_children),
dropping None descendants and hoisting nested type-less nodes at any
depth instead of leaving them embedded in the value.
- _group_top_level appends the final group with the last item's flag
rather than the loop's stale flags[i-1], so a trailing block node is no
longer wrapped as inline (which produced <p> inside <p>).
- finalize_slate collapses runs of consecutive whitespace-only paragraphs
to a single one via the new collapse_blank_paragraphs helper.
Updates the nested-divs fixture to the cleaner output and adds a
consolidation fixture.
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.
Summary
Three fixes for Slate conversion defects surfaced by a real-world Plone → Volto migration (Câmara Municipal de Uberlândia). Each defect produced output that either rendered incorrectly or could not be rendered by Volto at all.
Fixes
<span>text-decorationstyling dropped (#32)_span_mappedfont-weight/font-style/vertical-alignto Slate inline types but ignoredtext-decoration. Nowunderline→uandline-through→s(substring match, so CSS shorthand likeunderline dotted redworks). The style branches are collapsed into a small lookup table to stay under ruff's complexity limit.Trailing text after an inline run split out of its paragraph (#31)
A run of consecutive inline elements (e.g. two adjacent
<b>tags) followed by plain text had that text hoisted out of the parent<p>as a sibling block. Root cause:group_inline_nodestreated a plain text node as non-inline, breaking the inline run. Text nodes now continue the run (is_inline or is_simple_text).Deeply-nested
<div>structures produced non-renderable Slate (#33)Nested
<div>layouts generated invalid Slate —nullentries, type-less{children: [...]}nodes,<p>inside<p>, and bare text mixed with block siblings — all surfacing only at nesting depth. Three changes:_div_now returnsflatten_children(block_children), droppingNonedescendants and hoisting nested type-less nodes at any depth instead of hand-rolling child handling._group_top_levelappends the final group with the last item's flag rather than a staleflags[i-1], so a trailing block node preceded by an inline node is no longer wrapped as inline (which produced<p>in<p>).finalize_slatecollapses runs of consecutive whitespace-only paragraphs to a single one (newcollapse_blank_paragraphshelper) — an all-decorative section went from 34 empty paragraphs to 1.Tests
Closes #31
Closes #32
Closes #33