class

Crystal::SyntaxHighlighter::HTML

Inherits Crystal::SyntaxHighlighter / Reference / Object

A syntax highlighter that renders Crystal source code with HTML markup.

NOTE: To use Crystal::SyntaxHighlighter::HTML, you must explicitly import it with require "crystal/syntax_highlighter/html"

require "crystal/syntax_highlighter/html"

code = %(foo = bar("baz\#{PI + 1}") # comment)
html = Crystal::SyntaxHighlighter::HTML.highlight(code)
html # => "foo <span class=\"o\">=</span> bar(<span class=\"s\">&quot;baz</span><span class=\"i\">\#{</span><span class=\"t\">PI</span> <span class=\"o\">+</span> <span class=\"n\">1</span><span class=\"i\">}</span><span class=\"s\">&quot;</span>) <span class=\"c\"># comment</span>"

Constructors

new(io : IO)

Creates a new instance of an HTML syntax highlighter.

Appends highlighted output (when calling #highlight) to io.

Source

Class methods

highlight(io : IO, code : String)

Highlights code and writes the result to io.

Source
highlight(code : String)

Highlights code and returns the result.

Source
highlight!(code : String)

Highlights code or returns unhighlighted code on error.

Same as .highlight(code : String) except that any error is rescued and returns unhighlighted source code.

Source

Instance methods

render(type : TokenType, value : String)

Renders token with text value.

Source
render_delimiter

Renders a delimiter sequence.

Source
render_interpolation

Renders an interpolation sequence.

Source
render_string_array

Renders a string array sequence.

Source