1

我已经从Jean-Philippe Fleury为 markdown 编辑了 gtksourceview 语言文件。这是我的改进版本:https ://gist.github.com/ZelphirKaltstahl/de2b725ef5adba0a150dd27a5f7b66dc

这个使用markdown特定样式,我在一个也编辑过的样式文件中定义了它:https ://gist.github.com/ZelphirKaltstahl/f45be7bcedbc895df2439dd252d28c7b

这些文件我用于 GEdit。

但是,我还真的不满意。有这些properties用于定义评论在meta data. 它们已经匹配 html 注释,但是tommorow_night-eighties主题使用了一些颜色的注释,我不想在 markdown 文件中使用,但想在其他源代码文件中使用。

我想解决这个问题的想法是为这些属性添加一个减号,希望它们不再匹配 html 注释,并为 html 注释定义我自己的正则表达式并赋予另一种颜色。

在已包含的链接要点中,但不知何故无法正常工作。html 注释仍然根据元数据中的属性匹配和突出显示,我的正则表达式html-block-comment被忽略。

正则表达式是:

<!--
  (literally this kind of comment!)
  somehow still not working!
-->
<context id="html-block-comment" style-ref="html-block-comment">
  <match extended="true">
    ^.*          # at the beginning of the line an arbitrary amount of any characters
    (            # begin capture group 1
      &lt;!--    # the begin marker of an html comment
      [^&gt;]*   # everything except &gt;
    --&gt;       # the end marker of an html comment
    )            # end of capturing group 1
    .*$          # an arbitrary amount of any characters until line end
  </match>
</context>

我也已经将它包含在降价语法中(在最底部):

<context id="markdown-syntax">
  <include>
    <!-- Markdown contexts. -->
    <context ref="atx-header"/>
    <context ref="setext-header"/>
    <context ref="horizontal-rule"/>
    <context ref="list"/>
    <context ref="code-block"/>
    <context ref="1-backtick-code-span"/>
    <context ref="2-backticks-code-span"/>
    <context ref="blockquote"/>
    <context ref="automatic-link"/>
    <context ref="inline-link"/>
    <context ref="reference-link"/>
    <context ref="link-definition"/>
    <context ref="inline-image"/>
    <context ref="reference-image"/>
    <context ref="underscores-emphasis"/>
    <context ref="asterisks-emphasis"/>
    <context ref="underscores-strong-emphasis"/>
    <context ref="asterisks-strong-emphasis"/>
    <context ref="backslash-escape"/>
    <context ref="line-break"/>

    <!-- Markdown Extra contexts. -->
    <context ref="setext-header-id-attribute"/>
    <context ref="definition-list"/>
    <context ref="fenced-code-block"/>
    <context ref="footnote-reference"/>
    <context ref="abbreviation"/>
    <context ref="table-separator"/>
    <context ref="backslash-escape-extra"/>

    <!-- Xiaolong added -->
    <context ref="math-span-inline"/>
    <context ref="math-span-block"/>
    <context ref="html-block-comment"/>
  </include>
</context>

并且在 lang 文件的顶部有一个样式定义:

<styles>
  <!-- Markdown styles. -->
  <style id="header" _name="Header" map-to="def:type"/>
  <style id="horizontal-rule" _name="Horizontal Rule" map-to="def:type"/>
  <style id="code" _name="Code" map-to="def:identifier"/>
  <style id="blockquote-marker" _name="Blockquote Marker" map-to="def:shebang"/>
  <style id="label" _name="Label" map-to="def:preprocessor"/>
  <style id="attribute-value" _name="Attribute Value" map-to="def:constant"/>
  <style id="image-marker" _name="Image Marker" map-to="def:shebang"/>
  <style id="backslash-escape" _name="Backslash Escape" map-to="def:special-char"/>
  <style id="line-break" _name="Line Break" map-to="def:note"/>

  <!-- Xiaolong added styles -->
  <style id="list-marker" _name="List Marker" map-to="markdown:list-marker"/>
  <style id="math-inline" _name="Math Inline" map-to="markdown:single-math-marker"/>
  <style id="math-block" _name="Math Block" map-to="markdown:double-math-marker"/>
  <style id="url" _name="URL" map-to="markdown:url"/>
  <style id="link-text" _name="Link Text" map-to="markdown:link-text"/>
  <style id="emphasis" _name="Emphasis" map-to="markdown:emphasis"/>
  <style id="strong-emphasis" _name="Strong Emphasis" map-to="markdown:strong-emphasis"/>
  <style id="html-block-comment" _name="HTML Block Comment" map-to="markdown:html-block-comment"/>

  <!-- Markdown Extra styles. -->
  <style id="header-id-marker" _name="Header Id Marker" map-to="def:shebang"/>
  <style id="definition-list-marker" _name="Definition List Marker" map-to="def:shebang"/>
  <style id="footnote-marker" _name="Footnote Marker" map-to="def:shebang"/>
  <style id="abbreviation-marker" _name="Abbreviation Marker" map-to="def:shebang"/>
  <style id="abbreviation" _name="Abbreviation" map-to="def:preprocessor"/>
  <style id="table-separator" _name="Table Separator" map-to="def:statement"/>
</styles>

此样式映射到样式 XML 文件,其中我有定义:

<style name="markdown:html-block-comment" foreground="#303030" bold="false" italic="false"/>

所以我想我已经做好了一切,但显然不是这样。

我怎样才能使它只使用我的 html 评论的正则表达式?

4

0 回答 0