module

Hwaro::Content::Processors::SyntaxHighlighter

Syntax highlighter module for rendering markdown with highlighting support

Constants

SUPPORTED_LANGUAGES = Set.new(["bash", "c", "cpp", "csharp", "css", "crystal", "dart", "diff", "dockerfile", "elixir", "elm", "erlang", "go", "graphql", "groovy", "haskell", "html", "http", "ini", "java", "javascript", "json", "julia", "kotlin", "latex", "less", "lisp", "lua", "makefile", "markdown", "matlab", "nginx", "nim", "nix", "objectivec", "ocaml", "perl", "php", "plaintext", "powershell", "python", "r", "ruby", "rust", "scala", "scss", "shell", "sql", "swift", "toml", "typescript", "vim", "xml", "yaml", "zig"] of ::String)

List of supported languages for highlight.js (common ones)

THEMES = Set.new(["default", "a11y-dark", "a11y-light", "agate", "androidstudio", "an-old-hope", "arduino-light", "arta", "ascetic", "atom-one-dark", "atom-one-dark-reasonable", "atom-one-light", "brown-paper", "codepen-embed", "color-brewer", "dark", "devibeans", "docco", "far", "foundation", "github", "github-dark", "github-dark-dimmed", "googlecode", "gradient-dark", "gradient-light", "grayscale", "hybrid", "idea", "intellij-light", "ir-black", "isbl-editor-dark", "isbl-editor-light", "kimbie-dark", "kimbie-light", "lightfair", "lioshi", "magula", "mono-blue", "monokai", "monokai-sublime", "night-owl", "nnfx-dark", "nnfx-light", "nord", "obsidian", "ocean", "paraiso-dark", "paraiso-light", "panda-syntax-dark", "panda-syntax-light", "pojoaque", "purebasic", "qtcreator-dark", "qtcreator-light", "rainbow", "school-book", "shades-of-purple", "srcery", "stackoverflow-dark", "stackoverflow-light", "sunburst", "tokyo-night-dark", "tokyo-night-light", "tomorrow-night-blue", "tomorrow-night-bright", "vs", "vs2015", "xcode", "xt256", "zenburn"] of ::String)

Get CSS themes available for highlight.js

Instance methods

body_fingerprint

Fingerprint of module-level state that changes rendered body HTML.

Source
default_copy=(value : Bool)
Source
default_copy?
Source
default_line_numbers=(value : Bool)
Source
default_line_numbers?
Source
has_code_blocks?(content : String) : Bool

Check if content has code blocks that might benefit from highlighting

Source
language_supported?(lang : String) : Bool

Check if a language is supported

Source
render(content : String, highlight : Bool = true, safe : Bool = false, *, smart : Bool = false, tables_preprocessed : Bool = false, hooks : Content::Processors::RenderHooks::HookRenderContext | Nil = nil) : String

Render markdown to HTML with syntax highlighting enabled @param content - markdown content to render @param highlight - whether to enable syntax highlighting for code blocks @param safe - if true, raw HTML will not be passed through (replaced by comments) @param smart - if true, markd's smart punctuation rewrites straight quotes/dashes/ellipses in Text nodes (code spans, raw HTML, and the \x00 placeholders the extension passes leave are untouched) @param hooks - render-hook context (nil when no templates/hooks/render-* template is configured); when nil the renderer construction below is byte-identical to the pre-hooks code path.

Source
server_mode=(value : Bool)
Source
server_mode?
Source
theme_valid?(theme : String) : Bool

Check if a theme is valid

Source