You can highlight your own custom syntax by using this module!
One single styled portion of custom parsed code. Construct using
fragment or newline, and use it as the returned
value of your parser when using fromParser.
Constructs a Fragment value out of a part of the code you're parsing.
Typically should represent one syntactic unit in the code, such as a string,
an identifier, a keyword, an operator, whitespace, etc. You can add styling
details to this Fragment using setFragmentStyle and
setFragmentClasses.
Check the fromParser documentation for an example.
A special kind of Fragment: a way to insert an explicit break
into a new line when parsing your code. You can optionally pass it a
Highlight value to change how the following line
is rendered.
Please note that regular line breaks ('\n') in a fragment are interpreted
the same way as newline Nothing. So you don't really need to use this at all
unless you want to highlight a line in your custom syntax code.
Here's an example of how you can mark a line as “added” using this function.
import Parser
import SyntaxHighlight
import SyntaxHighlight.Custom as Custom
parser =
Parser.succeed
[ Custom.fragment "first line"
, Custom.newline (Some SyntaxHighlight.Add)
, Custom.fragment "added line"
, Custom.newline Nothing
, Custom.fragment "normal line"
]You can optionally use this function to give a Fragment one
or more custom CSS classes (separated by spaces), if you want more control over
how you style your custom syntax.
The style of a Fragment, whose actual appearance is given by the theme
that is applied. Construct using the different style* definitions provided,
and set it to a fragment using setFragmentStyle.
import SyntaxHighlight.Custom as Custom
aKeywordFragment =
Custom.fragment "case"
|> Custom.setFragmentStyle Custom.style3The default style for a fragment.
Style specific for comments.
Style typically used for keywords (alternative), group symbols ({}(),) and type signatures.
Use a parser from
elm/parserto define your own custom syntax. Your parser must produce a list ofFragmentvalues out of the code string.Here's a small example, to give you an idea of how to write your syntax. You can also check the custom syntax example in the repo.
import Html import Parser exposing (Parser) import SyntaxHighlight import SyntaxHighlight.Custom as Custom