AvalonEdit - 用于JSON突出显示的xshd

时间:2015-10-23 01:50:09

标签: wpf avalonedit

是否有AvalonEdit控件的xshd规则集突出显示JSON语法?我尝试了JavaScript的定义,但它不能很好地工作,即:

staticfloat/juliareleases

使用JavaScript定义,名称和值都具有相同的颜色。

是否有JSON的规则集,如果没有,我如何修改xshd以便在JSON中获得名称和值的不同颜色?

2 个答案:

答案 0 :(得分:7)

如果有人需要这样的东西,我会按照以下方式解决这个问题:

<?xml version="1.0" encoding="utf-8" ?>
<SyntaxDefinition name="Json" extensions=".js" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
  <Color name="Digits" foreground="#8700FF" exampleText="3.14" />
  <Color name="Value" foreground="#000CFF" exampleText="var text = &quot;Hello, World!&quot;;" />
  <Color name="ParamName" foreground="#057500"  exampleText="var text = &quot;Hello, World!&quot;;" />
  <RuleSet ignoreCase="false">
    <Keywords color="Digits" >
      <Word>true</Word>
      <Word>false</Word>
    </Keywords>
    <Span color="ParamName">
      <Begin>"</Begin>
      <End>(?=:)</End>
    </Span>
    <Span color="Value" multiline="true">
      <Begin>
        (?&lt;=:)\040"[^"]*
      </Begin>
      <End>"</End>
    </Span>
    <Rule color="Digits">\b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?</Rule>
  </RuleSet>
</SyntaxDefinition>

不完美,但对我来说还不够。

答案 1 :(得分:-1)

只需使用AvalonEdit's JavaScript highlighter

示例代码:

using (var stream = Assembly.GetAssembly(typeof(ICSharpCode.AvalonEdit.TextEditor)).GetManifestResourceStream("ICSharpCode.AvalonEdit.Highlighting.Resources.JavaScript-Mode.xshd"))
{
    using (var reader = new XmlTextReader(stream))
    {
        avalonEdit.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
        SearchPanel.Install(avalonEdit);
    }
}