Public Interface

Highlights Module

HighlightsModule.

Highlights.jl is a Julia package for source code highlighting. It provides a regular expression based mechanism for creating lexers in a similar way to Pygments.

The following names are exported from the root module, Highlights, and are available for external use. Note that unexported names are considered unstable and subject to change.

source
Highlights.highlightFunction.

Highlight source code using a specific lexer, mimetype and theme.

highlight(io, mime, src, lexer, theme)
highlight(io, mime, src, lexer)

src is tokenised using the provided lexer, then colourised using theme, and finally output to io in the given format mime. theme defaults to Themes.DefaultTheme theme.

mime can be either MIME("text/html") or MIME("text/latex").

Examples

julia> using Highlights

julia> highlight(STDOUT, MIME("text/html"), "2x", Lexers.JuliaLexer)
<pre class='hljl'>
<span class='hljl-ni'>2</span><span class='hljl-n'>x</span>
</pre>

julia> highlight(STDOUT, MIME("text/latex"), "'x'", Lexers.JuliaLexer, Themes.VimTheme)
\begin{lstlisting}
(*@\HLJLsc{{\textquotesingle}x{\textquotesingle}}@*)
\end{lstlisting}
source
Highlights.lexerMethod.
lexer(name)

Return the AbstractLexer associated with the lexer named name. name must be a string. Internally this checks the :aliases field in each lexer definition to see whether it is a match.

Warning

This method is not type stable.

When no lexer matches the given name an ArgumentError is thrown.

source
Highlights.stylesheetFunction.

Generate a "stylesheet" for the given theme.

stylesheet(io, mime, theme)
stylesheet(io, mime)

Prints out the style information needed to colourise source code in the given theme. Note that theme defaults to Themes.DefaultTheme. Output is printed to io in the format mime. mine can be one of

  • MIME("text/html")

  • MIME("text/css")

  • MIME("text/latex")

Examples

julia> using Highlights

julia> buf = IOBuffer();

julia> stylesheet(buf, MIME("text/css"), Themes.EmacsTheme)
source

Themes Submodule

Highlights.ThemesModule.

A submodule that provides a selection of themes that can be used to colourise source code.

source

The default colour scheme with colours based on the Julia logo.

source

A theme based on the Emacs colour scheme.

source

A GitHub inspired colour scheme.

source

A colour scheme similar to the Monokai theme.

source

Based on the default colour scheme used by the Pygments highlighter.

source

A Tango-inspired colour scheme.

source

Based on the default trac highlighter.

source

A Vim 7.0 based colour scheme.

source

A theme based on the default Visual Studio colours.

source

A theme based on the default Xcode colour scheme.

source
@S_str(spec)

Construct a Style object.

source
@theme(T, dict)

Declare the theme definition for theme T based on dict. dict must be a Dict and T must be a subtype of AbstractTheme.

Examples

julia> using Highlights.Themes

julia> abstract CustomTheme <: AbstractTheme

julia> @theme CustomTheme Dict(
           :name => "Custom",
           :tokens => Dict(
               # ...
           )
       );
source

Lexers Submodule

Highlights.LexersModule.

An exported submodule that provides a selection of lexer definitions for tokenising source code. The following names are exported from the module:

source

A FORTRAN 90 source code lexer.

source

A lexer for Julia REPL sessions.

source

A lexer for Julia source code.

source

A lexer for MATLAB source code.

source

A lexer for the R language.

source

TOML (Tom's Obvious, Minimal Language) lexer.

source
@lexer(T, dict)

Declare the lexer definition for a custom lexer T using a Dict object dict. dict must either be a Dict literal or an expression that returns a Dict – such as a let block.

Examples

julia> using Highlights.Lexers

julia> abstract CustomLexer <: AbstractLexer

julia> @lexer CustomLexer Dict(
           :name => "Custom",
           :tokens => Dict(
               # ...
           )
       );
source

Tokens Subtype

Highlights.TokensModule.

This submodule provides a collection of token names for use in lexer and theme definitions. The table shown below lists all the exported tokens as well as the abbreviations used when printing stylesheets and highlighted source code.

TokenAbbreviation
TEXTt
WHITESPACEw
ESCAPEe
ERROReB
OTHERo
KEYWORDk
KEYWORD_CONSTANTkc
KEYWORD_DECLARATIONkd
KEYWORD_NAMESPACEkn
KEYWORD_PSEUDOkp
KEYWORD_RESERVEDkr
KEYWORD_TYPEkt
NAMEn
NAME_ATTRIBUTEna
NAME_BUILTINnb
NAME_BUILTIN_PSEUDOnbp
NAME_CLASSnc
NAME_CONSTANTncB
NAME_DECORATORnd
NAME_ENTITYne
NAME_EXCEPTIONneB
NAME_FUNCTIONnf
NAME_FUNCTION_MAGICnfm
NAME_PROPERTYnp
NAME_LABELnl
NAME_NAMESPACEnn
NAME_OTHERno
NAME_TAGnt
NAME_VARIABLEnv
NAME_VARIABLE_CLASSnvc
NAME_VARIABLE_GLOBALnvg
NAME_VARIABLE_INSTANCEnvi
NAME_VARIABLE_MAGICnvm
LITERALl
LITERAL_DATEld
STRINGs
STRING_AFFIXsa
STRING_BACKTICKsb
STRING_CHARsc
STRING_DELIMITERsd
STRING_DOCsdB
STRING_DOUBLEsdC
STRING_ESCAPEse
STRING_HEREDOCsh
STRING_INTERPOLsi
STRING_OTHERso
STRING_REGEXsr
STRING_SINGLEss
STRING_SYMBOLssB
NUMBERnB
NUMBER_BINnbB
NUMBER_FLOATnfB
NUMBER_HEXnh
NUMBER_INTEGERni
NUMBER_INTEGER_LONGnil
NUMBER_OCTnoB
OPERATORoB
OPERATOR_WORDow
PUNCTUATIONp
COMMENTc
COMMENT_HASHBANGch
COMMENT_MULTILINEcm
COMMENT_PREPROCcp
COMMENT_PREPROCFILEcpB
COMMENT_SINGLEcs
COMMENT_SPECIALcsB
GENERICg
GENERIC_DELETEDgd
GENERIC_EMPHge
GENERIC_ERRORgeB
GENERIC_HEADINGgh
GENERIC_INSERTEDgi
GENERIC_OUTPUTgo
GENERIC_PROMPTgp
GENERIC_STRONGgs
GENERIC_SUBHEADINGgsB
GENERIC_TRACEBACKgt
source