Scriban template syntax support
I am using the EditControl to edit scriban-templates. (https://github.com/scriban/scriban/blob/master/doc/language.md)
Inside a scriban template there are "code blocks" in which you can define keywords, variables, etc.
I have already created a basic working configuration for syntax highlighting.
My question: how to I make keywords only highlight when they are inside a code block?
{{ for myItem in myCollection }}
This is part of the output for loop number {{ for.index }}
{{ end }}
In the example above the keyword "for" should only be highlighted when it is inside a {{ }} block.
Attachment: scriban_template_8664bb1c.png
I found a solution (I think, at least it works).
I nested 2 elements of <lexem BeginBlock="{" EndBlock="}" />
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfConfigLanguage>
<ConfigLanguage name="Scriban">
<formats>
<format name="Text" Font="Consolas, 10pt" FontColor="Black" />
<format name="KeyWord" Font="Consolas, 10pt, style=Bold" FontColor="Blue" />
<format name="String" Font="Consolas, 10pt" FontColor="#A31515" />
<format name="Comment" Font="Consolas, 10pt, style=Italic" FontColor="Green" />
<format name="Operator" Font="Consolas, 10pt, style=Bold" FontColor="#FF6600" />
<format name="Parameter" Font="Consolas, 10pt" FontColor="Purple" />
<format name="Function" Font="Consolas, 10pt" FontColor="#8B4513" />
<format name="Number" Font="Consolas, 10pt" FontColor="DarkCyan" />
</formats>
<extensions>
<extension>scriban</extension>
</extensions>
<lexems>
<lexem BeginBlock="{" EndBlock="}" Type="Operator" OnlyLocalSublexems="false" IsComplex="true">
<SubLexems>
<lexem BeginBlock="{" EndBlock="}" Type="Operator" OnlyLocalSublexems="false" IsComplex="true">
<SubLexems>
<lexem BeginBlock="end" Type="KeyWord" />
<lexem BeginBlock="for" Type="KeyWord" />
<lexem BeginBlock="in" Type="KeyWord" />
</SubLexems>
</lexem>
</SubLexems>
</lexem>
</lexems>
<splits>
</splits>
</ConfigLanguage>
</ArrayOfConfigLanguage>
How do I add support for a single line comment and a multiline comment?
Within a code block, scriban supports single line comments # and multi-line comments ##:
{{ name # this is a single line comment }}Multiline comments runs unit a closing ## is found
{{ ## This
is a multi
line
comment ## this not }}
Hi Dieter,
Thank you for your query regarding Scriban comment support in the EditControl. Scriban supports both single-line and multi-line comments within code blocks, and you can configure them in the syntax definition as follows:
Single-line comments: Begin with
#and continue until the end of the line.Multi-line comments: Begin with
##and continue until the next closing##.
In your configuration, you can add these lexems inside the Scriban code block:
// Single-line comment (# until newline) codeBlock.SubLexems.Add(new ConfigLexem { StartText = "#", EndText = "\n", FormatName = "Comment" }); // Multi-line comment (## ... ##) codeBlock.SubLexems.Add(new ConfigLexem { StartText = "##", EndText = "##", FormatName = "Comment", IsComplex = true }); |
This ensures that both comment styles are highlighted correctly inside {{ ... }} blocks.
With this configuration, single-line and multi-line comments will be recognized and styled as expected.
Regards,
Aravindhan Periyasamy
Dear Aravindhan,
Thanks for your response.
Unfortunately this does not work. I already looked at other examples. For example when using "/*" and "*/", than it seems to work. But there seems to be a problem with the specific "##" and "##" combination. I also have an issue with "{{" and "}}" which only work if the following word is stick to it. when there is a space after {, it doesn't work.
I also tried adding the "{{" and "##" blocks to the <split>-section in the config.xml file.
I have included my config.xml file in attachment together with a sample file and a screenshot of the output.
I would appreciate it if you could take a closer look at it.
Thanks in advance,
Dieter
Attachment: scriban_template_support_problem_39b77b26.zip
Hi Dieter,
Thank you for sharing the details along with your config.xml, sample file, and screenshot.
We analyzed the source and confirmed that the "##" comment style is not supported. Currently, only the "/* ... */" and "(* ... *)" symbols are provided for comment handling. We tried possible workarounds for the "##" combination, but they did not work as expected. We recommend using the supported symbols mentioned above.
Regarding the issue with "{{" and "}}" where it only worked if the following word was directly attached, we have fixed this behavior. A sample has been attached for your reference. Could you please review the attached sample and let us know if it resolves the issue on your end?
Regards,
Aravindhan Periyasamy
Attachment: EditControlScribanTemplates_286ce1b1.zip
- 5 Replies
- 2 Participants
-
DM Dieter Moeyersons
- Jan 18, 2026 06:22 PM UTC
- Jan 29, 2026 01:12 PM UTC