💾 Archived View for makeworld.space › amfora-wiki › Source-Code-Highlighting.gmi captured on 2023-11-04 at 11:37:36. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-07-16)
-=-=-=-=-=-=-
Opening or streaming non text files
--------------------------------------------------------------------------------
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:
<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.
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.
styles
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.
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.
If you'd like to support Amfora development, you can sponsor me through Ko-Fi or Github Sponsors. Feel free to submit a PR as well! Thanks.