-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Escape indented code block before render #4179
Escape indented code block before render #4179
Conversation
Code highlighting might be unnecessary for indented code blocks. |
Yeah, there's no way for indented code blocks to add language mark. |
54a68e4
to
843a12d
Compare
What about adding test cases above to see if it can handle the situation. Update The current approach can not handle the second case above correctly. |
@SukkaW I updated. |
@seaoak I get a better idea. |
Users may use tags in nested list
|
78d65d1
to
fbac10a
Compare
As @stevenjoezhang 's commnet, @SukkaW 's idea can not be used. |
They might be many other cases that should be covered:
And if the regexp is over complicated, the performance might be affected. |
The condition to recognize "indented code block" is not so complicated. Only in blockquote, the condition is a bit more complicated. I think it is acceptable. |
const rIndentedCodeBlock = /(^|(?:^|\n)(?:(?: {0,3}>){1,3}[^\S\r\n])?[^\S\r\n]*\n)((?:((?:(?: {0,3}>){1,3}[^\S\r\n])?)( {4}|\t)([^\n]*?)(\n|$))+)/g; | ||
|
||
function indentedCodeBlock(data) { | ||
data.content = data.content.replace(rIndentedCodeBlock, ($0, before, content, start, $4, $5, end) => { |
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.
data.content = data.content.replace(rIndentedCodeBlock, ($0, before, content, start, $4, $5, end) => { | |
// Return early if there is no 4 consecutive spaces for better performance | |
if (!data.content.includes(' ')) return; | |
data.content = data.content.replace(rIndentedCodeBlock, ($0, before, content, start, $4, $5, end) => { |
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.
To support single-tab-indented code block, this optimization can not be used.
I Updated. |
Unfortunately, I awake to the danger that this filter spoils indented codes in code block tag. For example,
this filter escapes the line 7-8 with I have no idea to resolve this. 😢 |
I'll discard this patch. |
What does it do?
Supplement of the PR #4171, for the issue #4087.
Since the PR #4171 changes rendering order,
Nunjucks tags in indented code blocks become targets of rendering by Nunjucks.
This is undesirable.
This situation can be observed in the issue #4087.
This patch escapes Nunjucks tags in indented code blocks before rendering by Nunjucks.
How to test
Pull request tasks