marked icon indicating copy to clipboard operation
marked copied to clipboard

Issues with Parsing Nested Emphasis and Handling Chinese Parentheses

Open inorywww opened this issue 1 year ago • 1 comments

Description

I've encountered several issues with the marked library where the parsing of nested emphasis and handling of Chinese parentheses does not behave as expected. Below are the specific cases with their actual and expected outputs:

import { marked } from 'marked'

  1. Case 1: Direct Nested Bold within Italic (No Surrounding Text)

    • Code: console.log('marked case1', marked('_**abcd123**_'));
    • Actual Output: <p><em><strong>abcd123</strong></em></p> (As expected)
  2. Case 2: Italic Nested Bold (With Surrounding Text)

    • Code: console.log('marked case2', marked('abcd_**123**_'));
    • Actual Output: <p>abcd_<strong>123</strong>_</p>
    • Expected Output: <p>abcd<em><strong>123</strong></em></p>
  3. Case 3: Bold Nested Italic

    • Code: console.log('marked case3', marked('abcd**_123_**'));
    • Actual Output: <p>abcd**<em>123</em>**</p>
    • Expected Output: <p>abcd<strong><em>123</em></strong></p>
  4. Case 4: Italic Nested Chinese Parentheses

    • Code: console.log('marked case4', marked('abcd_(123)_'));
    • Actual Output: <p>abcd_(123)_</p>
    • Expected Output: <p>abcd<em>(123)</em></p>

Steps to Reproduce

The code snippets provided above under each case can be used to reproduce the issues.

Expected Behavior

For each of the cases listed above, I expected the marked library to parse and render the Markdown as described in the "Expected Output" sections.

Actual Behavior

However, the actual outputs for cases 2, 3, and 4 do not match the expected behavior, indicating issues with parsing nested emphasis and handling text within Chinese parentheses.

Additional Information

  • Marked version: 12.0.0
  • Browser/Node version: Chrome 121.0.6167.139 (arm64)/v16.19.0

I hope this information helps in diagnosing and fixing the issues. Thank you for your efforts in maintaining this library.

inorywww avatar Feb 07 '24 09:02 inorywww

Marked tries to follow the CommonMark spec. As you can see all of these cases follow the spec.

case 1: marked demo CommonMark demo case 2: marked demo CommonMark demo case 3: marked demo CommonMark demo case 4: marked demo CommonMark demo

UziTech avatar Feb 07 '24 15:02 UziTech