mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 06:33:06 -03:00
feat: higher level API (to_html
and to_ansi
)
Some checks failed
Tests / build (push) Has been cancelled
Some checks failed
Tests / build (push) Has been cancelled
This commit is contained in:
29
README.md
29
README.md
@ -45,18 +45,35 @@ $ tartrazine whatever.c -t catppuccin-macchiato --line-numbers \
|
||||
|
||||
## Usage as a Library
|
||||
|
||||
This works:
|
||||
This is the high level API:
|
||||
|
||||
```crystal
|
||||
require "tartrazine"
|
||||
|
||||
lexer = Tartrazine.lexer("crystal")
|
||||
theme = Tartrazine.theme("catppuccin-macchiato")
|
||||
formatter = Tartrazine::Html.new
|
||||
formatter.theme = theme
|
||||
puts formatter.format(File.read(ARGV[0]), lexer)
|
||||
html = Tartrazine.to_html(
|
||||
"puts \"Hello, world!\"",
|
||||
language: "crystal",
|
||||
theme: "catppuccin-macchiato",
|
||||
standalone: true,
|
||||
line_numbers: true
|
||||
)
|
||||
```
|
||||
|
||||
This does more or less the same thing, but more manually:
|
||||
|
||||
```crystal
|
||||
lexer = Tartrazine.lexer("crystal")
|
||||
formatter = Tartrazine::Html.new (
|
||||
theme: Tartrazine.theme("catppuccin-macchiato"),
|
||||
line_numbers: true,
|
||||
standalone: true,
|
||||
)
|
||||
puts formatter.format("puts \"Hello, world!\"", lexer)
|
||||
```
|
||||
|
||||
The reason you may want to use the manual version is to reuse
|
||||
the lexer and formatter objects for performance reasons.
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it (<https://github.com/ralsina/tartrazine/fork>)
|
||||
|
Reference in New Issue
Block a user