Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅✨Allow br tags in more elements, add tests #1403

Merged
merged 6 commits into from
Jan 8, 2025

Conversation

cathysarisky
Copy link
Contributor

@cathysarisky cathysarisky commented Dec 17, 2024

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!)

@cathysarisky cathysarisky marked this pull request as ready for review December 17, 2024 02:07
Copy link
Contributor

@9larsons 9larsons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm not bothered by the loss of the space when combining spans, as that content isn't contained in an element/node.

I would like to have @kevinansfield review before merging.

@cathysarisky cathysarisky changed the title Better fix for br issue? maybe? Allow br tags in more elements, add tests Jan 8, 2025
@cathysarisky cathysarisky changed the title Allow br tags in more elements, add tests ✅✨Allow br tags in more elements, add tests Jan 8, 2025
@kevinansfield kevinansfield merged commit 1b63462 into TryGhost:main Jan 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Newlines not correctly handled in product card titles
3 participants