diff --git a/packages/rich-text/src/parser/MdParser.js b/packages/rich-text/src/parser/MdParser.js index 7d970ca6c..8f2a0d1ca 100644 --- a/packages/rich-text/src/parser/MdParser.js +++ b/packages/rich-text/src/parser/MdParser.js @@ -15,8 +15,8 @@ const codes = { char: "*", domEl: "strong", encodedChar: 0x2a, - // see https://regex101.com/r/evswdV/6 for explanation of regexp - regexString: "\\B\\*((?!\\s)[^*]+)\\b\\*\\B", + // see https://regex101.com/r/evswdV/8 for explanation of regexp + regexString: "\\B\\*((?!\\s)[^*]+(?:\\b|[^*\\s]))\\*\\B", contentFn: val => val, }, italic: { @@ -24,8 +24,8 @@ const codes = { char: "_", domEl: "em", encodedChar: 0x5f, - // see https://regex101.com/r/p6LpjK/5 for explanation of regexp - regexString: "\\b_((?!\\s)[^_]+)\\B_\\b", + // see https://regex101.com/r/p6LpjK/6 for explanation of regexp + regexString: "\\b_((?!\\s)[^_]+(?:\\B|[^_\\s]))_\\b", contentFn: val => val, }, emoji: { diff --git a/packages/rich-text/src/parser/__tests__/MdParser.spec.js b/packages/rich-text/src/parser/__tests__/MdParser.spec.js index 31eea687d..2272c03d0 100644 --- a/packages/rich-text/src/parser/__tests__/MdParser.spec.js +++ b/packages/rich-text/src/parser/__tests__/MdParser.spec.js @@ -62,6 +62,10 @@ describe('MdParser class', () => { ['_italic_ and *bold* with a example.com/link_with_underscore', 'italic and bold with a example.com/link_with_underscore'], ['example.com/path with *bold* after :)', 'example.com/path with bold after \u{1F642}'], ['_before_ example.com/path_with_underscore *after* :)', 'before example.com/path_with_underscore after \u{1F642}'], + + // italic/bold markers right after non-word characters + ['_If % of ART retention rate after 12 months >90(%)_: Sustain the efforts.', 'If % of ART retention rate after 12 months >90(%): Sustain the efforts.'], + ['*If % of ART retention rate after 12 months >90(%)*: Sustain the efforts.', 'If % of ART retention rate after 12 months >90(%): Sustain the efforts.'], ]; tests.forEach((test) => {