Syntax highlighting in Elm.
Transform a highlighted code into a Html block.
The Maybe Int argument is for showing or not line count and, if so, starting from what number.
Transform a highlighted code into inline Html.
import SyntaxHighlight exposing (elm, toInlineHtml)
info : Html msg
info =
p []
[ text "This function signature "
, elm "isEmpty : String -> Bool"
|> Result.map toInlineHtml
|> Result.withDefault
(code [] [ text "isEmpty : String -> Bool" ])
, text " means that a String argument is taken, then a Bool is returned."
]Transform a highlighted code into a static (pure text) Html block. The Maybe Int argument is for showing or not line count and, if so, starting from what number.
Transform a highlighted code into static (pure text) inline Html.
Highlight type.
Highlight will highlight the line in a way to differentiate it from the rest, like github's yellow background.Add will highlight in a manner that gives the ideia of new content added.Del will highlight in a manner that gives the ideia of removed content.The specific styles will depend on the chosen Theme.
Highlight lines given a highlight type, start and end index.
If no highlight type is given (Nothing), it will remove any
highlight from the line range.
Negative indexes are taken starting from the end of the list.
Error while parsing should not happen. If it happens, please open an issue with the code that gives the error and the language.
Parse Javascript syntax.
A theme defines the background and syntax colors.
Transform a theme into Html. Any highlighted code transformed into Html in the same page will be themed according to the chosen Theme.
To preview the themes, check out the demo.
import SyntaxHighlight exposing (elm, monokai, toBlockHtml, useTheme)
view : Model -> Html msg
view model =
div []
[ useTheme monokai
, elm model.elmCode
|> Result.map (toBlockHtml (Just 1))
|> Result.withDefault
(pre [] [ code [] [ text model.elmCode ] ])
]If you prefer to use CSS external stylesheet, you do not need this, just copy the theme CSS into your stylesheet. All themes can be found here.
Console styling options. You can use the rtfeldman/console-print package to fill in the styles.
The common uses of the styles are the following:
Transform a highlighted code into a list of console highlighted strings given the styling options defined by ConsoleOptions.
Each string in the list is a line.
Custom transform options. The common uses of the styles are the following:
A highlighted code.