-
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
fix: Code and heading after list without blank line #2483
Conversation
fix: behavior of fenced code block following list. fix: behavior of heading following list.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
While this PR does work, at this point it's starting to look like we are going to end up replicating the entirety of the "Paragraph" interruption RegEx that we already have in For instance, we should also be interrupting list items with "headers", "blockquotes", and "HTML" which we don't do correctly if we compare to the commonmark Dingus: Marked Demo, Commonmark Demo There must be some way we can just incorporate the existing interruption regex here rather than re-implementing each one, which results in code duplication and a lot of complexity to the Lists tokenizer. @UziTech thoughts? |
I agree. I think we should apply similar logic as the paragraph. It might still have to be duplicated since it won't be able to break on lists like the paragraph. |
@@ -0,0 +1,7 @@ | |||
<ol> | |||
<li>abcd<pre><code>if { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is not supposed to be part of the list item. CommonMark demo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UziTech
Thanks for the review.
My misunderstanding.
I thought that Marked's behavior of code blocks was aimed at a different behavior than CommonMark.
I will fix it and commit to it.
I will conform to CommonMark's behavior as follows.
-
No indentation
CommonMark demo1
Note: The CommonMark demo site cannot keep spaces in permalinks, so I have attached two images.
Followed the behavior of CommonMark.js.
@UziTech |
src/Tokenizer.js
Outdated
@@ -223,6 +223,15 @@ export class Tokenizer { | |||
endEarly = true; | |||
} | |||
|
|||
const fencesBeginRegExp = new RegExp(`^( {0,${indent}})(\`\`\`|~~~)`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the 2nd if statement if this only checked {0, ${indent - 1}}
?
src/Tokenizer.js
Outdated
if (fencesBeginRegExp.test(src)) { // Items begin with at most one code block | ||
const fenceBeginCap = fencesBeginRegExp.exec(src); | ||
// if End list item if found non-indented fenced code block | ||
if (fenceBeginCap[1].length < indent) { | ||
endEarly = true; | ||
} | ||
} | ||
|
||
if (!endEarly) { | ||
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`); | ||
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (fencesBeginRegExp.test(src)) { // Items begin with at most one code block | |
const fenceBeginCap = fencesBeginRegExp.exec(src); | |
// if End list item if found non-indented fenced code block | |
if (fenceBeginCap[1].length < indent) { | |
endEarly = true; | |
} | |
} | |
if (!endEarly) { | |
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`); | |
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`); | |
if (!endEarly) { | |
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`); | |
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`); | |
const fencesBeginRegex = new RegExp(`^( {0,${Math.min(3, indent - 1)}})(\`\`\`|~~~)`); |
Then below you can do a simpler test:
// End list item if found code fences
if (fencesBeginRegex.test(line)) {
break;
}
@UziTech @calculuschild |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is fine. I have ideas to maybe speed this up in the future but it will take a little more tinkering.
## [4.0.17](v4.0.16...v4.0.17) (2022-06-13) ### Bug Fixes * Code and heading after list without blank line ([#2483](#2483)) ([15f3f15](15f3f15))
🎉 This PR is included in version 4.0.17 🎉 The release is available on: Your semantic-release bot 📦🚀 |
fixed behavior of fenced code block following list.
fixed behavior of heading following list.
Marked version:
4.0.16
Markdown flavor:
GitHub Flavored Markdown
Description
Contributor
Committer
In most cases, this should be a different person than the contributor.