Documentation
inko-syntax
A simple syntax highlighting library for Inko, with Pygments compatible HTML output.
This library focuses solely on syntax highlighting, and doesn't provide any means to detect a language/lexer to use according to a file extension, filename, MIME type, or the file contents.
Requirements
- Inko 0.17.0 or newer
Installation
inko pkg add github.com/yorickpeterse/inko-syntax 0.16.0
inko pkg sync
Supported languages
- C:
c
(aliased ascpp
) - Fish:
fish
- Inko:
inko
- Make:
make
- Ruby:
ruby
- Rust:
rust
- Shell:
shell
(aliases asbash
,sh
,zsh
,ksh
) - TOML:
toml
Supported formats
- Pygments compatible HTML
Usage
A basic example:
import std.stdio (STDOUT)
import syntax (Languages)
import syntax.format (Html)
class async Main {
fn async main {
# The `Languages` type is a registry of the available languages. This type
# makes it easy to create a lexer for a language, without having to
# explicitly import the underlying types into your code.
let langs = Languages.new
# This gets a language for the given name, returning a `None` if the name
# isn't recognized.
let lang = langs.get('inko').unwrap
# Now we can create a lexer and format it. Lexers take an immutable
# reference to a `ByteArray`, so we need to keep it around until we've
# produced the token stream.
let bytes = '# This is a test'.to_byte_array
let lexer = lang.lexer(bytes)
# The `Html` formatter takes a lexer and turns it into Pygments compatible
# HTML document fragment.
let html = Html.new.format(lexer)
STDOUT.new.print(html.to_string)
}
}
The output of this is the following HTML (formatted manually to increase readability):
<div class="highlight">
<pre class="highlight"><code><span class="c"># This is a test</span></code></pre>
</div>
For more information, refer to the API documentation.
License
All source code in this repository is licensed under the Mozilla Public License version 2.0, unless stated otherwise. A copy of this license can be found in the file "LICENSE".
Modules
syntax | A simple syntax highlighting library for Inko. |
syntax.format | Formatting of token streams as HTML. |
syntax.lexer.c | Lexical analysis of C syntax. |
syntax.lexer.fish | Lexical analysis of Fish syntax. |
syntax.lexer.inko | Lexical analysis of Inko syntax. |
syntax.lexer.make | Lexical analysis of Make/Makefile syntax. |
syntax.lexer.ruby | Lexical analysis of Ruby syntax. |
syntax.lexer.rust | Lexical analysis of Rust syntax. |
syntax.lexer.shell | Lexical analysis of Bash/shell syntax. |
syntax.lexer.toml | Lexical analysis of TOML syntax. |