Prism.js 仅在行首突出显示
Prism.js highlight only if it begins the line
我正在为 Prism.js 编写自定义语言扩展,但在突出显示注释时遇到问题。我想突出显示以 #
或 //
开头并从行首开始的注释:
# Example comment
// Example comment
1*2//comment <-- this should not be highlighted
这是我用来检测评论的模式:/(^|[^\])[#\/\/].*/
。
不幸的是,它没有按预期工作:
我尝试使用 lookbehind
和 greedy
选项 (docs),但没有帮助。
通过将正则表达式更改为 /(^|^\)(\/{2}|#).*/gm
来修复
我正在为 Prism.js 编写自定义语言扩展,但在突出显示注释时遇到问题。我想突出显示以 #
或 //
开头并从行首开始的注释:
# Example comment
// Example comment
1*2//comment <-- this should not be highlighted
这是我用来检测评论的模式:/(^|[^\])[#\/\/].*/
。
不幸的是,它没有按预期工作:
我尝试使用 lookbehind
和 greedy
选项 (docs),但没有帮助。
通过将正则表达式更改为 /(^|^\)(\/{2}|#).*/gm