【问题标题】:Prism.js highlight only if it begins the linePrism.js 仅在开始行时突出显示
【发布时间】:2020-03-08 11:37:54
【问题描述】:

我正在为 Prism.js 编写自定义语言扩展,但在突出显示 cmets 时遇到问题。我想突出显示以 #// 开头并从行首开始的 cmets:

# Example comment
// Example comment
1*2//comment <-- this should not be highlighted

这是我用来检测 cmets 的模式:/(^|[^\\])[#\/\/].*/

不幸的是,它没有按预期工作:

我尝试使用 lookbehindgreedy 选项 (docs),但没有帮助。

【问题讨论】:

    标签: javascript prismjs


    【解决方案1】:

    通过将正则表达式更改为/(^|^\\)(\/{2}|#).*/gm 修复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多