-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Paste: Enable space before heading text ~ handle Hex/# value #69229
base: trunk
Are you sure you want to change the base?
Paste: Enable space before heading text ~ handle Hex/# value #69229
Conversation
73d5906
to
5b1c93e
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Hi @Mamaduka here's a PR for the issue. cc: @im3dabasia |
Not sure if this is intended behaviour but discovered while testing the PR Screen.Recording.2025-02-18.at.7.26.34.PM.mov |
Thanks! @Mayank-Tripathi32 I was able to reproduce the issue. This occurs when we undo it and paste the value again on the same line. This is a tangential case, as it occurs without this change as well. I traced this back to the use of gutenberg/packages/block-editor/src/components/writing-flow/use-clipboard-handler.js Line 147 in 9d1a2ce
gutenberg/packages/block-editor/src/components/writing-flow/use-clipboard-handler.js Line 172 in 9d1a2ce
When undoing the paste, the following code triggers a selection reset leading to treating it as a block, gutenberg/packages/block-editor/src/store/reducer.js Lines 1398 to 1403 in 9d1a2ce
Not sure if this means this is expected?! |
I don't believe this should be the expected behavior, but someone with more experience may be able to provide more insight! cc: @WordPress/gutenberg-core |
What?
Closes #69221
This PR updates the Markdown converter by enabling the requireSpaceBeforeHeadingText option in the showdown configuration. This change ensures that headings are only recognized when there is a space between the hash (#) and the heading text.
Why?
Previously, when hex values/hashtags (e.g. #Heading) were pasted, the # were stripped out, leading to issues as described in #69221. By requiring a space after the heading marker, the converter now adheres to standard Markdown practices, reducing rendering inconsistencies.
How?
The solution was implemented by modifying the showdown converter options. Specifically, we set requireSpaceBeforeHeadingText to true. This forces the converter to only treat strings as headings when space between "#" and the title(# Heading) is used. Subsequently, strings representing hex values/hastags remains intact.
Testing Instructions
Screenshots or screencast
Before:-
Screen.Recording.2025-02-18.at.12.48.54.PM.mov
On enabling this:-
If a hex value is pasted(with no space), it retains the #.
1739855513192526.mp4
If a value with a space is pasted, it behaves as expected.
1739855543722253.mp4