Skip to content

Commit

Permalink
fix: correctly detect italic/bold marker after non-word char (DHIS2-9…
Browse files Browse the repository at this point in the history
…382) (#624)
  • Loading branch information
edoardo authored Sep 3, 2020
1 parent 81c48ea commit cc17ac7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/rich-text/src/parser/MdParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ 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: {
name: "italic",
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: {
Expand Down
4 changes: 4 additions & 0 deletions packages/rich-text/src/parser/__tests__/MdParser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ describe('MdParser class', () => {
['_italic_ and *bold* with a example.com/link_with_underscore', '<em>italic</em> and <strong>bold</strong> with a <a href="http://example.com/link_with_underscore">example.com/link_with_underscore</a>'],
['example.com/path with *bold* after :)', '<a href="http://example.com/path">example.com/path</a> with <strong>bold</strong> after <span>\u{1F642}</span>'],
['_before_ example.com/path_with_underscore *after* :)', '<em>before</em> <a href="http://example.com/path_with_underscore">example.com/path_with_underscore</a> <strong>after</strong> <span>\u{1F642}</span>'],

// italic/bold markers right after non-word characters
['_If % of ART retention rate after 12 months >90(%)_: Sustain the efforts.', '<em>If % of ART retention rate after 12 months &gt;90(%)</em>: Sustain the efforts.'],
['*If % of ART retention rate after 12 months >90(%)*: Sustain the efforts.', '<strong>If % of ART retention rate after 12 months &gt;90(%)</strong>: Sustain the efforts.'],
];

tests.forEach((test) => {
Expand Down

0 comments on commit cc17ac7

Please sign in to comment.