Code2HTML icon indicating copy to clipboard operation
Code2HTML copied to clipboard

Subpatterns

Open Col-E opened this issue 5 years ago • 2 comments

Lets say I have the following text:

<span class="code">pom.xml</span>

I can make a rule that registers <span class="code"> and </span> as HTML tags (<[\s\w="\/;'.,:?-]+>), but I then want to look inside the matched region and match keywords like class and strings. I can't do this with single-level patterns. This will need sub-patterns to accomplish.

Col-E avatar Apr 19 '19 07:04 Col-E

Been a while, but getting around to this with a large refactor of the project.

Having distinct <themes> declaring style independent from the <rule> items in a <language> was neat and all, letting there be multiple themes... but its also a bit of a pain to maintain the two separate blocks.

A sample of the new Java language XML looking specifically at the javadoc-comment rule.

<language name="Java">
 ...
  <rule name="javadoc-comment">
    <pattern>/[*]{2}(?:.|\n)+?\*/</pattern>
    <style>
        <entry key="color" value="rgb(0, 100, 114)" />
              <entry key="font-style" value="italic" />
    </style>
    <subrules>
        <rule name="field">
          <pattern>\B(?:@[\w]+)\b</pattern>
          <style>
              <entry key="font-weight" value="bold" />
          </style>
        </rule>
        <rule name="param-name">
           <pattern>(?&lt;=@param)\s+\b(?:\w+)\b</pattern>
           <style>
                <entry key="color" value="rgb(0, 50, 60)" />
           </style>
        </rule>
    </subrules>
  </rule>
...
</language>

Output looks like: image

Col-E avatar Nov 27 '22 08:11 Col-E

Having a "recursive" flag would be nice for subrules. Esp for xml styled languages.

Col-E avatar Nov 27 '22 10:11 Col-E