Skip to content

fix(react):fix(react): prevent intra-word and whitespace-flanked markdown emphasis in composer - #1418

Open
swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1372-composer-markdown-emphasis
Open

swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1372-composer-markdown-emphasis

Conversation

@swarnendusahu10-dotcom

Copy link
Copy Markdown
Contributor

Description

Fixes #1372

In the AI contentEditable composer (contentEditableComposer.js), markdown emphasis regex patterns did not adhere to CommonMark/GFM flanking specifications. As a result:

  • Variable names, file paths, and snake_case identifiers (e.g., my_file_name.js, user_id_token) had their inner words corrupted into italic <em> tags (e.g., my<em>file</em>name.js).
  • Arithmetic expressions or standalone asterisks surrounded by whitespace (e.g., 2 * 3 * 4) were erroneously parsed as bold/italic.

Cause & Solution

  • Underscores (_): Per CommonMark specs, underscores cannot open or close emphasis if preceded or followed by word characters (non-word boundary requirement). Updated regex requires word boundaries/non-word characters so snake_case identifiers remain literal.
  • Asterisks (*): Required whitespace non-flanking checks so asterisks used in math or bullet contexts are not parsed as emphasis formatting.
  • Zero Domino Effect: Formatting applied via formatting toolbars or explicit markdown delimiters (*bold*, _italic_) outside words continue to work seamlessly.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Verified with comprehensive test cases:
    • Intra-word snake_case: my_file_name.js, foo_bar_baz, variable_name -> preserved untouched.
    • Arithmetic expressions: 2 * 3 * 4, 10 / 2 * 5 -> preserved untouched.
    • Standard bold and italics: *italic*, **bold**, _italic_, __bold__ -> formatted correctly into <em> and <strong>.
    • Nested formatting: **_bold and italic_** -> formatted correctly.
  • Prettier code style check passed cleanly.

…hasis in composer

Prevents intra-word underscores and whitespace-flanked asterisks from
being parsed as emphasis in contentEditableComposer.js.

CommonMark and GFM specify that underscore delimiters cannot open or close
emphasis when adjacent to word characters, and emphasis markers cannot be
flanked by whitespace. Previously, identifiers (e.g. my_file_name.js,
foo_bar_baz) and arithmetic (e.g. 2 * 3 * 4) were corrupted into
<em> and <strong> tags when rendered in the composer.

Fixes RocketChat#1372

This branch has not been deployed

No deployments
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.

bug: AI composer renders intra-word _ and * as italic/bold (e.g. my_file_name.js -> my<em>file</em>name.js)

1 participant