-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Italic/bold is treated as a list, When Italic/bold is written on the next line of the list #1980
Comments
You "editor" link doesn't have a Can you provide the markdown that has a problem? |
Thanks for the reproduction. It looks like this may be unspecified behavior. Are you looking for something closer to the commonmark demo where the bold line is part of the previous list item or is the bold not supposed to be in the list at all? |
I think this issue is a list-only issue. As a test, compare "marked" and "commonmark" with list problems (without Italic / bold) For commonmark, each list has 2 lists. This is the cause of "Italic/bold is treated as a list" |
If you would like to create a PR we could get your patch merged. |
Looks like this is mostly solved by #2112. There is still a difference of Marked creating |
I have came upon this issue as well, having problems like the demo above. TLDR;
What is wrongHere's what I have understood through reading the
I've found that while var itemRegex = new RegExp(`^( {0,3}${bull})((?: [^\\n]*)?(?:\\n|$))`);
// |^( {0,3}${bull})((?: [^\\n]*)?(?:\\n|$))|
// 1. |^| : start of sentence
// 2. | {0,3}| : 0~3 spaces available
// 3. |${bull}| : pre-computed bullet character
// 4. |( [^\\n]*)?|: a space, optionally followed by non-newline characters (optional)
// 5. |(\\n|$)| : end of sentence, or new line
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])`);
// |^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])|
// 1. |^ | : start of sentence, followed by a space
// 2. |{0,${Math.min(3, indent - 1)}}|: zero to some predefined indent number of spaces (string evaluation)
// 3. |([*+-]|\\d{1,9}[.)])| : any item bullet, either ordered or unordered
//
// NOTE does not check whether there is any whitespace after the bullet. Say we have a smaller sample (demo): - item1
- item2
-Not a list item(without space)
- item3 The current implementation of Lines 241 to 243 in 4c5b974
On next iteration it figures that The fix (or, fixes)I tried changing //const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])`);
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`); Indeed this will render the above sample correctly, These all have the form of 'bullet-like' block syntax inside the list, mingled with various indent options and precedences over each other (setext heading has higher order than thematic breaks). Maybe the reason Additional TouchI did manage to make all tests pass, with adding additional logic inside the second loop. while (src) {
rawLine = src.split('\n', 1)[0];
prevLine = line;
line = rawLine;
// ...
if (this.rules.block.hr.test(line)) {
// make sure it is not a setext heading, which takes precedence
const twoLines = [prevLine, line].join('\n');
const matchLheadingPattern = this.rules.block.lheading.test(twoLines);
const lineIdentIsLargerThanPrev = line.search(/[^ ]/) >= indent;
const isNextLineSetextHeading = matchLheadingPattern && lineIdentIsLargerThanPrev;
if (!isNextLineSetextHeading) {
break;
}
}
// End list item if found start of new bullet
if (nextBulletRegex.test(line)) {
break;
}
// ...
} Adding this code solves the issue, and make all the tests pass as well. I am a bit afraid that the list tokenizer is getting more and more complex, but honestly I don't know if there is any other way (Frankly speaking it seems that markdown syntax is complicated by nature). If there is a better way to do it in marked, I would like to hear about it. Or if this is fine to go on and make a PR? Thanks. |
This makes marked render correctly with the following text: ```markdown - item1 - item2 -Not a list item(without space) - item3 ``` Currently: ```html <ul> <li>item1</li> <li>item2</li> </ul> <p>-Not a list item(without space)</p> <ul> <li>item3</li> </ul> ``` Which should be: ```html <ul> <li>item1</li> <li>item2 -Not a list item(without space)</li> <li>item3</li> </ul> ``` This is the rendered result for commonmark as well. Changes: - `nextBulletRegex` checks for whitespace after the bullet - separately checks for hr or lheading
@jangxyz a PR would be appreciated 😁👍 |
This makes marked render correctly with the following text: ```markdown - item1 - item2 -Not a list item(without space) - item3 ``` Currently: ```html <ul> <li>item1</li> <li>item2</li> </ul> <p>-Not a list item(without space)</p> <ul> <li>item3</li> </ul> ``` Which should be: ```html <ul> <li>item1</li> <li>item2 -Not a list item(without space)</li> <li>item3</li> </ul> ``` This is the rendered result for commonmark as well. Changes: - `nextBulletRegex` checks for whitespace after the bullet - separately checks for hr or lheading
🎉 This issue has been resolved in version 4.0.15 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Marked version:
master
Describe the bug
To be exact, this problem is
After recognizing the list, determine whether the next line is the next list only by the symbol(without space) of the list.
In detail
The next line after the line recognized as a list
The next line is the symbol(* ,+ ,- ,1.) used in the list followed by a character without space.
In the above case, marked determines that the next line is also a list.
Therefore, "*" is used in the list symbol, so if there is an "*" in the next line, it is judged as a list.
To Reproduce
editor
Expected behavior
I applied the following self-made patch to this problem.
note
This sentence is through google translate.
Did you get the content?
The text was updated successfully, but these errors were encountered: