text processing utilities

Highlight documentation

Highlight News

Some details of the recent changes mentioned in the ChangeLog.

improved `--force` fallback argument handling

If --force has an argument, this will now also work for normal file input (not just IO redirection), making it easier to define a fallback syntax.

added C++ attribute syntax support

C++11 attributes are highlighted as keyword group 5.

added Lua fuction `StoreValue` to set and retrieve information across Lua states

Sometimes it would be useful to exchange information between Lua states. As syntax and theme lua chunks are executed in their own states, information could not be shared.
This might be confusing for average Highlighting Joe because all chunks are defined in one Lua script. He and/or she wants to define a variable which should be accessible in all functions like Decorate and OnStateChange? This now can be achieved with the new StoreValue function. Call it with two parameters to set a value, call it with one to read it back.

The first plug-in which makes use of this is mark_lines.lua. First a value is stored in the themeUpdate chunk:

  if (HL_OUTPUT == HL_FORMAT_TRUECOLOR) then
    StoreValue("ansiOpenSeq", lighten(Canvas.Colour, "\x1B[48;2;%02x;%02x;%02xm"))
  elseif (HL_OUTPUT == HL_FORMAT_HTML or HL_OUTPUT == HL_FORMAT_XHTML) then
    Injections[#Injections+1]=".hl.mark { background-color:"..lighten(Canvas.Colour, "#%02x%02x%02x")
  elseif (HL_OUTPUT == HL_FORMAT_RTF) then
    table.insert(Keywords, {Colour=lighten(Canvas.Colour, "#%02x%02x%02x")})
  end
Later it is read in the syntaxUpdate chunk:
  ansiOpenSeq = StoreValue("ansiOpenSeq")

added `extras/eclipse-themes/eclipse_color_themes.py` script

This small script will access the huge theme database of eclipsecolorthemes.org/.
It pulls the XML file of the given theme id and creates a highlight theme file. You now have about 12.000 more themes to choose from.

python ./eclipse_color_themes.py 1234
Retrieving Theme #1234...
Saving Highlight Theme File evig_morke.theme...

added support for Web Assembly Text

Yet another syntax.

updated mark_lines.lua to output 16m terminal sequences

The plug-in was enhanced to work with terminal sequences, adding up to RTF and HTML output.

highlight test.sh -sgreenlcd --plug-in mark_lines.lua --plug-in-param '25,27,26' -l

fixed issues in bash.lang

File paths which contained "share" were not highlighted correctly.

fixed Bash heredoc highlighting in bash_functions.lua

If a plug-in uses a hook function which is already used in a syntax related to the plug-in, the original hook chunks need to be saved and executed explicitly. This was done in the Bash plug-in.

CLI: `highlight --version -q` only prints the version number

If highlight is used in a script or in a GUI, it might be helpful to quickly determine its version without parsing the verbose --version output. If version is combined with the quiet option, it will only output the version number.

highlight --version -q
3.58

GUI: added theme contrast indicator

This value is calculated based on the canvas and default font colours of the selected theme. If the value is below 4.5, an exclamation mark will indicate a poor contrast value.
(See webaim.org for more details.


Found on the Internetz

fzf quick search

As mentioned in a bug report, I recently found fzf, a fast interactive search utility. It can make use of highlight when an environment variable is set like this:

export FZF_DEFAULT_OPTS="--ansi --preview '(highlight -O truecolor -sgreenlcd -l {} 2>/dev/null || cat {}) 2>/dev/null | head -200'"

SourceCodeSyntaxHighlight

There are several MacOS Quicklook plug-ins available which invoke highlight for the pretty-printing. One of the most comfortable variants is SourceCodeSyntaxHighlight. You can even change the color settings in its UI.
So if you are one of the Apple fans try this out.

reprex

The reprex package is part of the R universe. It can be used to generate reproducible examples, ie. to use in bug reports.
More details about its configuration are also available.

Tupel7