3 Source Code Highlighting
makeworld edited this page 2021-12-23 00:19:51 -05:00

This feature is currently only available on the master branch. It will be available in a published release in Amfora v1.10.0 and later.


Make sure that you've read the configuration wiki page first.

By default Amfora will automatically attempt to highlight blocks of preformatted source code. This is accomplished by searching for a string at the start of the alt text; if the string corresponds to a supported language name or MIME type, then the syntax will be highlighted if possible.

Example Gemtext:

```HTML example
<p>Hello world!</p>
```

Because the word "HTML" was present at the start of the preformatted block's alt text, Amfora will attempt to read and highlight this as HTML code. This matching is case-insensitive, so html or Html would also work, as would text/html for matching based on media type.

Amfora will split the string at the first character that is not either an alphanumeric character or one of the following characters (all valid in media types per RFC 6838 or used in language names): ! _ # $ - ^ . +.

Any language supported by Chroma is supported by Amfora.

Configuration

This feature can be enabled or disabled by the highlight_code flag in the configuration file.

You can change the style to any style supported by Chroma by changing the highlight_style string in the configuration file. A list of supported styles is available, with examples.

Amfora attempts to determine the number of colors supported by your terminal, which is then used by Chroma's syntax highlighter. This should work most of the time, even in recent versions of Windows.

Note to Gemtext authors

When preparing your Gemtext for use with this feature, it is recommended to use the language name rather than the media type, and (if necessary due to lack of context) to provide a short description. This is helpful for people who use screen readers.