✅✨Allow br tags in more elements, add tests #1403
Merged
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.
Closes TryGhost/Ghost#20027
Current situation (prior to merge of #1404 and this PR):
Quirk 1: Some card editor components respond to shift-enter by creating what looks like a second line in the editor, but it saves as two spans (not separated by a br). Upon reload of the post in the editor, the two spans are combined. (Editor components affected: Product card title, toggle title.)
Quirk 2: Shift enter results in two lines in the editor that save as two spans with a br, but upon reload in the editor, the two are mashed into a single span. (Editor components affected: Header title and subheading, all three signup card components.)
Both behaviors are undesirable, because they cause the appearance of the card in the editor not to match what appears on the published page, and because re-opening a post should not change those components that are not edited.
Enabling shift-enter in additional components also allows a little more flexibility/extensibility of these cards. (For example, a product card 'title' could be used to show a heading and subheading.)
In my first attempt to address the problem (#21076, now reverted), I ran afoul of a gap in the testing setup. Tests of the exporting function were only in kg-default-nodes, but koenig-lexical extends the exportJSON behavior to include an additional cleaning step. These changes were not covered by the existing koenig-lexical test setup, which is predominantly browser-based, and never triggers the exportJSON function.
I've also added a new set of unit tests to koenig-lexical that specifically test loading strings into the editor (in headless form) and exporting them for saving via the exportJSON functions defined in that package. These tests should be much closer to what's really going to happen in the Ghost editor than what's available in kg-default-nodes.
Suggested TODO (not in this PR): Add additional unit tests in koenig-lexical for any other nodes that are extending exportJSON.
Tests revealed an additional problem with span smooshing fixed over in #1404 (Thanks Kevin!)