fix(react): apply CommonMark flanking rules to composer emphasis - #1376
Open
ishan-one8 wants to merge 2 commits into
Open
ishan-one8 wants to merge 2 commits into
ishan-one8 wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
Apply CommonMark flanking rules to composer emphasis
Root cause.
appendMarkdowninpackages/react/src/lib/contentEditableComposer.jstreated any_,*,__or**as an emphasis delimiter and paired it with the next identical marker, without ever checking whether that delimiter run was allowed to open or close emphasis. CommonMark decides that with the left/right-flanking rules and additionally forbids intra-word_, so any underscore or asterisk with another one later in the line opened emphasis.Fixes #1372
Acceptance Criteria fulfillment
my_file_name.js,call foo_bar_baz() nowand2 * 3 * 4 = 24render literally again**bold**,*italic*,__init__,a _b_ cand intra-wordfoo*bar*bazstill render as emphasis<br>paths untouchedyarn buildstill producesdist/cjsanddist/esm(exit 0)Video/Screenshots
Not applicable — no visible UI change beyond the corrected text rendering, which the tests cover.
PR Test Details
Two commits:
test(react): emit CommonJS under the test env so jest can run—babel.config.jshadmodules: falseunconditionally, sobabel-jesthanded ESM to jest and every test file died with "Cannot use import statement outside a module". It now emits CommonJS only whenapi.env('test')is true; the rollup build still gets native ES modules, which is why the bundle output is unchanged. Also adds the missingtestscript. This is the same area as fix(react): src/index.test.js fails on develop due to missing swiper/element/bundle module #1191.fix(react): apply CommonMark flanking rules to composer emphasis— addscanOpenEmphasis/canCloseEmphasis/findClosingMarkerand uses them when selecting a delimiter. When the nearest matching marker cannot close, the scan continues to the next one instead of giving up.Before the fix, the new test fails:
After it,
yarn testinpackages/reactpasses 3/3.I also diffed the fixed renderer against the reference
commonmarkpackage across 13 emphasis cases — includingfoo*bar*baz,snake_case and _real_ emphasis,_leading,trailing_and5 * 6— and all 13 now match.