icsharpcode / AvalonEdit

The WPF-based text editor component used in SharpDevelop
http://avalonedit.net/
MIT License
1.85k stars 471 forks source link

Highlighting #354

Closed NotroDev closed 2 years ago

NotroDev commented 2 years ago

Hi. I have this in my xaml for code highlighting:

<Span color="String">
    <Begin>"</Begin>
    <End>"</End>
</Span>

And yeah, it's working. But, i want to add a rule that will override it. Eg. i have a rule that highlights text between {}. And i want it to highlight in "" too. Like this: obraz

How can i do this?

siegfriedpammer commented 2 years ago

This is probably what you want:

<?xml version="1.0"?>
<SyntaxDefinition name="Custom Highlighting" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
    <Color name="Comment" foreground="Green" />
    <Color name="String" foreground="Blue" />
    <Color name="BracedExpression" foreground="Orange" />

    <RuleSet>
        <Span color="String" ruleSet="BracedExpressionRuleSet">
            <Begin>"</Begin>
            <End>"</End>
        </Span>

        <Import ruleSet="BracedExpressionRuleSet" />
    </RuleSet>

    <RuleSet name="BracedExpressionRuleSet">
        <Span color="BracedExpression">
            <Begin>{</Begin>
            <End>}</End>
        </Span>
    </RuleSet>
</SyntaxDefinition>
NotroDev commented 2 years ago

This is probably what you want:

<?xml version="1.0"?>
<SyntaxDefinition name="Custom Highlighting" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
  <Color name="Comment" foreground="Green" />
  <Color name="String" foreground="Blue" />
  <Color name="BracedExpression" foreground="Orange" />

  <RuleSet>
      <Span color="String" ruleSet="BracedExpressionRuleSet">
          <Begin>"</Begin>
          <End>"</End>
      </Span>

      <Import ruleSet="BracedExpressionRuleSet" />
  </RuleSet>

  <RuleSet name="BracedExpressionRuleSet">
      <Span color="BracedExpression">
          <Begin>{</Begin>
          <End>}</End>
      </Span>
  </RuleSet>
</SyntaxDefinition>

Yes, it's working perfectly! Thanks! :D

NotroDev commented 2 years ago

Hey, sorry, but I have new problems... This:

<Keywords foreground="#FF5555">
    <Word>&amp;c</Word>
</Keywords>

Is working like this: obraz Why? I want it to be always highlighted.

And... I have this:

<Span color="Command">
    <Begin>command </Begin>
    <End>:</End>
    <RuleSet>
        <!-- nested span for escape sequences -->
        <Span begin="#"/>
    </RuleSet>
</Span>

It's working okay in what i want: obraz But... "command" is red also in the normal text: obraz

And i have a question.

I have colors like this: obraz

How can i make it to look like this? obraz I hope you understand.

(Eg. &a is green, and all text after &a is green (until a new color appears, eg. &b)

(Sorry, i don't understand regex etc)

NotroDev commented 2 years ago

This is probably what you want:

<?xml version="1.0"?>
<SyntaxDefinition name="Custom Highlighting" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
  <Color name="Comment" foreground="Green" />
  <Color name="String" foreground="Blue" />
  <Color name="BracedExpression" foreground="Orange" />

  <RuleSet>
      <Span color="String" ruleSet="BracedExpressionRuleSet">
          <Begin>"</Begin>
          <End>"</End>
      </Span>

      <Import ruleSet="BracedExpressionRuleSet" />
  </RuleSet>

  <RuleSet name="BracedExpressionRuleSet">
      <Span color="BracedExpression">
          <Begin>{</Begin>
          <End>}</End>
      </Span>
  </RuleSet>
</SyntaxDefinition>

To my last reply. I can use this code:

<Span foreground="#FF5555">
    <Begin>&amp;c</Begin>
    <End>&amp;</End>
</Span>

But it colors next & too. I just need to remove it and it will be great...