icsharpcode / AvalonEdit

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

CSS Style Tag In HTML #313

Closed ArunPatal closed 2 years ago

ArunPatal commented 2 years ago

Hello,

I tried to add following lines in HTML-Mode.xshd, but it's not working. I need to highlight css in html document. (using 5.0.4)

<Span ruleSet="StyleSet" multiline="true">
    <Begin color="StyleTag">&lt;style&gt;</Begin>
    <End color="StyleTag">&lt;/style&gt;</End>
</Span>

<RuleSet name="StyleSet">
    <Import ruleSet="CSS/" />
    <Rule color="Digits">\b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?</Rule>
</RuleSet>
siegfriedpammer commented 2 years ago

The problem is that the built-in CSS definition is not yet registered when the HTML definition is loaded:

https://github.com/icsharpcode/AvalonEdit/blob/a6273d114953dd72bebecad2a9df2c0022138039/ICSharpCode.AvalonEdit/Highlighting/Resources/Resources.cs#L35-L64

I suggest, you define a custom HTML highlighting, which should be registered after the built-in highlightings are loaded.

ArunPatal commented 2 years ago

The problem is that the built-in CSS definition is not yet registered when the HTML definition is loaded:

https://github.com/icsharpcode/AvalonEdit/blob/a6273d114953dd72bebecad2a9df2c0022138039/ICSharpCode.AvalonEdit/Highlighting/Resources/Resources.cs#L35-L64

I suggest, you define a custom HTML highlighting, which should be registered after the built-in highlightings are loaded.

Hi,

How about if i change source like below... Will css be loaded before html is loaded?

hlm.RegisterHighlighting("JavaScript", new[] { ".js" }, "JavaScript-Mode.xshd"); hlm.RegisterHighlighting("CSS", new[] { ".css" }, "CSS-Mode.xshd"); hlm.RegisterHighlighting("HTML", new[] { ".htm", ".html" }, "HTML-Mode.xshd");

ArunPatal commented 2 years ago

It work, as you (Siegfried Pammer) mentioned css was not registered so changed position of css-mode as above code. I also added below line in HTML-Mode.xshd

<Color name="StyleTag" foreground="#FF8B008B" exampleText="&lt;style&gt; h1{color:red;}&lt;/style&gt;" />