markedjs / marked

A markdown parser and compiler. Built for speed.
https://marked.js.org
Other
32.98k stars 3.39k forks source link

Link with underscores and parantheses wrapped in underscores is parsed incorrectly #3468

Closed Brakebein closed 1 day ago

Brakebein commented 2 weeks ago

Marked version: 14.1.2

Describe the bug A link is not parsed correctly if it contains underscores and parantheses, and is itself wrapped with underscores (e.g. for styling italics). Pattern: _[Link title](https://domain.org/link_with_underscores_(parantheses))_

To Reproduce Open Marked demo link. In CommonMark Demo it is displayed correctly.

  1. Marked Demo_%20some%20more%20text%0A%0A&options=%7B%0A%20%22async%22%3A%20false%2C%0A%20%22breaks%22%3A%20false%2C%0A%20%22extensions%22%3A%20null%2C%0A%20%22gfm%22%3A%20true%2C%0A%20%22hooks%22%3A%20null%2C%0A%20%22pedantic%22%3A%20false%2C%0A%20%22silent%22%3A%20false%2C%0A%20%22tokenizer%22%3A%20null%2C%0A%20%22walkTokens%22%3A%20null%0A%7D&version=14.1.2)
  2. CommonMark Demo_%20some%20more%20text)

Expected behavior Only (interactive) link title should be displayed with italics/bold styling (see CommonMark demo).

UziTech commented 2 weeks ago

Looks like this is because of the way we parse the strong\em we need to try to make sure the end is not inside a link

The workaround is to use * for the italics. Demo*%20some%20more%20text%0A%0A&options=%7B%0A%20%22async%22%3A%20false%2C%0A%20%22breaks%22%3A%20false%2C%0A%20%22extensions%22%3A%20null%2C%0A%20%22gfm%22%3A%20true%2C%0A%20%22hooks%22%3A%20null%2C%0A%20%22pedantic%22%3A%20false%2C%0A%20%22silent%22%3A%20false%2C%0A%20%22tokenizer%22%3A%20null%2C%0A%20%22walkTokens%22%3A%20null%0A%7D&version=14.1.2)