bobzhang/pygments/formatters does not have a README file

    FormatterClass

    type FormatterClass = (FormatterInfo, (Map[String, String],
    Style
    ?) -> Formatter raise)

    A formatter class: its metadata and constructor (options, optional style overriding the style option).

    Tokens

    A token stream: (token type, text) pairs, as produced by @lexer.Lexer::get_tokens.

    ClassNotFound

    pub suberror ClassNotFound {
    ClassNotFound(String)
    } derive(
    Debug
    )

    Raised when no formatter matches a lookup (Python's ClassNotFound).

    FormatterError

    pub suberror FormatterError {
    FormatterError(String)
    } derive(
    Debug
    )

    Errors raised by formatters (Python's ValueError/RuntimeError/...).

    AuxFile

    pub(all) struct AuxFile {
    path : String
    contents : String
    noclobber : Bool
    } derive(
    Debug
    )

    A file that Python's formatter writes as a side effect of format (the HTML formatter's cssfile). This port does no file IO: the caller writes contents to path, which Python resolves relative to the directory of the output file (or the current directory when the output has no name) unless it is absolute; with noclobber an existing file is kept.

    BaseOptions

    pub struct BaseOptions {
    style :
    Style

    full : Bool
    title : String
    encoding : String?
    options : Map[String, String]
    }

    The options every formatter accepts (Python's Formatter.__init__).

    BaseOptions::new

    fn BaseOptions::new(options : Map[String, String], style? :
    Style
    ) -> BaseOptions raise

    Parses the common options. style overrides the style option (like passing a Style class in Python).

    Formatter

    pub struct Formatter {
    info : FormatterInfo
    base : BaseOptions
    // private fields
    }

    A formatter instance: converts a token stream to text.

    Formatter::aliases

    fn Formatter::aliases(self : Formatter) -> Array[String]

    The formatter's aliases.

    Formatter::aux_files

    fn Formatter::aux_files(self : Formatter) -> Array[AuxFile]

    The files Python would write while formatting (see AuxFile).

    Formatter::filenames

    fn Formatter::filenames(self : Formatter) -> Array[String]

    The formatter's file name patterns.

    Formatter::format

    fn Formatter::format(self : Formatter, tokens : Array[(
    TokenType
    , String)]) -> String raise

    Python's Formatter.format: the formatted text of tokens.

    Formatter::get_style_defs

    fn Formatter::get_style_defs(self : Formatter, arg? : String) -> String raise

    Python's get_style_defs(arg): style definitions for the current style (e.g. CSS rules for HTML). Omitting arg is Python's arg=None; the pygmentize -S command line passes arg (default "").

    Formatter::name

    fn Formatter::name(self : Formatter) -> String

    The formatter's human-readable name.

    Formatter::new

    fn Formatter::new(info : FormatterInfo, base : BaseOptions, format : (Array[(
    TokenType
    , String)]) -> String raise, style_defs? : (String?) -> String raise, aux_files? : () -> Array[AuxFile]) -> Formatter

    Wraps the operations of a formatter class.

    Formatter::options

    fn Formatter::options(self : Formatter) -> Map[String, String]

    The options the formatter was created with.

    Formatter::style

    The style the formatter uses.

    FormatterInfo

    pub(all) struct FormatterInfo {
    class_name : String
    name : String
    aliases : Array[String]
    filenames : Array[String]
    description : String
    } derive(
    Debug
    )

    Static metadata of a formatter class.

    HtmlFormatter

    pub struct HtmlFormatter {
    base : BaseOptions
    nowrap : Bool
    noclasses : Bool
    classprefix : String
    cssclass : String
    cssstyles : String
    prestyles : String
    cssfile : String
    noclobber_cssfile : Bool
    tagurlformat : String
    filename : String
    wrapcode : Bool
    debug_token_types : Bool
    linenos : Int
    linenostart : Int
    linenostep : Int
    linenospecial : Int
    nobackground : Bool
    lineseparator : String
    lineanchors : String
    linespans : String
    anchorlinenos : Bool
    hl_lines : Array[Int]
    // private fields
    }

    Python's HtmlFormatter. Every option of the Python class is supported except tagsfile (needs the ctags module; rejected) and the writing of cssfile: with full and cssfile the document links to the file, and cssfile_contents returns the text Python would write to it.

    HtmlFormatter::cssfile_contents

    fn HtmlFormatter::cssfile_contents(self : HtmlFormatter) -> String

    The text Python writes to cssfile when full and cssfile are given (this port does not write files; see noclobber_cssfile).

    HtmlFormatter::format

    fn HtmlFormatter::format(self : HtmlFormatter, tokens : Array[(
    TokenType
    , String)]) -> String raise FormatterError

    Python's format: the HTML for tokens.

    test {
    let f = @formatters.HtmlFormatter::new()
    inspect(
    f.format([(@token.keyword, "def"), (@token.text, " f\n")]),
    content=(
    #|<div class="highlight"><pre><span></span><span class="k">def</span> f
    #|</pre></div>
    #|
    ),
    )
    }

    HtmlFormatter::get_background_style_defs

    fn HtmlFormatter::get_background_style_defs(self : HtmlFormatter, arg? : String) -> Array[String]

    Python's get_background_style_defs(arg).

    HtmlFormatter::get_background_style_defs_for

    fn HtmlFormatter::get_background_style_defs_for(self : HtmlFormatter, args : Array[String]) -> Array[String]

    Python's get_background_style_defs with a list of selectors.

    HtmlFormatter::get_css_prefix

    fn HtmlFormatter::get_css_prefix(self : HtmlFormatter, cls : String, arg? : String) -> String

    Python's get_css_prefix(arg) applied to cls.

    HtmlFormatter::get_linenos_style_defs

    fn HtmlFormatter::get_linenos_style_defs(self : HtmlFormatter) -> Array[String]

    Python's get_linenos_style_defs.

    HtmlFormatter::get_style_defs

    fn HtmlFormatter::get_style_defs(self : HtmlFormatter, arg? : String) -> String

    Python's get_style_defs(arg) (arg omitted is Python's None).

    HtmlFormatter::get_style_defs_for

    fn HtmlFormatter::get_style_defs_for(self : HtmlFormatter, args : Array[String]) -> String

    Python's get_style_defs with a list of selectors: every rule is prefixed by each of args.

    HtmlFormatter::get_token_style_defs

    fn HtmlFormatter::get_token_style_defs(self : HtmlFormatter, arg? : String) -> Array[String]

    Python's get_token_style_defs(arg).

    HtmlFormatter::get_token_style_defs_for

    fn HtmlFormatter::get_token_style_defs_for(self : HtmlFormatter, args : Array[String]) -> Array[String]

    Python's get_token_style_defs with a list of selectors.

    HtmlFormatter::new

    fn HtmlFormatter::new(options? : Map[String, String], style? :
    Style
    ) -> HtmlFormatter raise

    Creates an HTML formatter from options (see Python's documentation of HtmlFormatter for the option names).

    HtmlFormatter::to_formatter

    fn HtmlFormatter::to_formatter(self : HtmlFormatter) -> Formatter

    Wraps the HTML formatter as a generic Formatter.

    LatexFormatter

    pub struct LatexFormatter {
    base : BaseOptions
    nowrap : Bool
    docclass : String
    preamble : String
    linenos : Bool
    linenostart : Int
    linenostep : Int
    verboptions : String
    nobackground : Bool
    commandprefix : String
    texcomments : Bool
    mathescape : Bool
    escapeinside : String
    envname : String
    // private fields
    }

    Python's LatexFormatter: LaTeX fancyvrb output. Options: style, full, title, docclass, preamble, nowrap, linenos, linenostart, linenostep, verboptions, commandprefix, texcomments, mathescape, escapeinside, envname (and nobackground, which Python accepts but ignores).

    LatexFormatter::format

    fn LatexFormatter::format(self : LatexFormatter, tokens : Array[(
    TokenType
    , String)]) -> String

    Python's format: the LaTeX for tokens.

    LatexFormatter::get_style_defs

    fn LatexFormatter::get_style_defs(self : LatexFormatter) -> String

    Python's get_style_defs: the macro definitions for the current style (the argument is ignored).

    LatexFormatter::new

    fn LatexFormatter::new(options? : Map[String, String], style? :
    Style
    ) -> LatexFormatter raise

    Creates a LaTeX formatter from options.

    LatexFormatter::to_formatter

    fn LatexFormatter::to_formatter(self : LatexFormatter) -> Formatter

    Wraps the LaTeX formatter as a generic Formatter.

    ansiformat

    fn ansiformat(attr : String, text : String) -> String raise FormatterError

    Python's pygments.console.ansiformat: text in a color, where *color* is bold, _color_ underlined and +color+ blinking.

    bbcode_formatter

    fn bbcode_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's BBCodeFormatter. Options: style, codetag, monofont.

    bbcode_info

    let bbcode_info : FormatterInfo

    Metadata of Python's BBCodeFormatter.

    colorize

    fn colorize(color_key : String, text : String) -> String raise FormatterError

    Python's pygments.console.colorize.

    console_codes

    let console_codes : Map[String, String]

    Python's pygments.console.codes: ANSI escape sequences by name.

    escape_tex

    fn escape_tex(text : String, commandprefix : String) -> String

    Python's latex.escape_tex: escapes TeX special characters with \<commandprefix>Zxx{} macros.

    find_formatter_class

    fn find_formatter_class(name : String) -> (FormatterInfo, (Map[String, String],
    Style
    ?) -> Formatter raise)?

    Python's find_formatter_class: the formatter class with alias.

    get_all_formatters

    fn get_all_formatters() -> Array[FormatterInfo]

    Python's get_all_formatters: metadata of every formatter.

    get_formatter_by_name

    fn get_formatter_by_name(name : String, options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's get_formatter_by_name: an instance of the formatter with alias, configured with options.

    test {
    let f = @formatters.get_formatter_by_name("html", options={ "nowrap": "true" })
    inspect(
    f.format([(@token.keyword, "if")]),
    content="<span class=\"k\">if</span>\n",
    )
    }

    get_formatter_for_filename

    fn get_formatter_for_filename(filename : String, options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's get_formatter_for_filename: an instance of the formatter whose file name patterns match the base name of filename.

    test {
    inspect(
    @formatters.get_formatter_for_filename("out/a.tex").name(),
    content="LaTeX",
    )
    }

    groff_formatter

    fn groff_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's GroffFormatter. Options: style, monospaced, linenos, wrap. As in Python, the line counter and the current line length continue across format calls.

    groff_info

    let groff_info : FormatterInfo

    Metadata of Python's GroffFormatter.

    highlight

    fn highlight(code : String, lexer :
    Lexer
    , formatter : Formatter) -> String raise

    Python's pygments.highlight: lexes code with lexer (including its filters) and formats the tokens with formatter.

    html_info

    let html_info : FormatterInfo

    Metadata of Python's HtmlFormatter.

    irc_colors

    fn irc_colors() -> Map[
    TokenType
    , (String, String)]

    Python's irc.IRC_COLORS: (light background, dark background) color names per token type.

    irc_formatter

    fn irc_formatter(options? : Map[String, String], style? :
    Style
    , colorscheme? : Map[
    TokenType
    , (String, String)]) -> Formatter raise

    Python's IRCFormatter (options bg, linenos; colorscheme as a map). As in Python, the line counter continues across format calls.

    irc_info

    let irc_info : FormatterInfo

    Metadata of Python's IRCFormatter.

    ircformat

    fn ircformat(color : String, text : String) -> String raise FormatterError

    Python's irc.ircformat: text wrapped in IRC color/attribute codes.

    latex_embedded_lexer

    fn latex_embedded_lexer(left : String, right : String, lang :
    Lexer
    , options? : Map[String, String]) ->
    Lexer
    raise

    Python's LatexEmbeddedLexer: lexes with lang, but text between the delimiters left and right outside strings and comments becomes an Escape token (raw LaTeX for the LatexFormatter). The options of lang are inherited; options override them.

    latex_info

    let latex_info : FormatterInfo

    Metadata of Python's LatexFormatter.

    null_formatter

    fn null_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's NullFormatter: the token texts, concatenated.

    null_info

    let null_info : FormatterInfo

    Metadata of Python's NullFormatter.

    pango_info

    let pango_info : FormatterInfo

    Metadata of Python's PangoMarkupFormatter.

    pango_markup_formatter

    fn pango_markup_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's PangoMarkupFormatter. Options: style.

    raw_token_formatter

    fn raw_token_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's RawTokenFormatter: one Token.Type<TAB>'text' line per token (Python's b"%r\t%r\n", i.e. ASCII-only reprs). Options: error_color (colorize Error tokens) and compress (only "" and "none" are supported; gz/bz2 need compression libraries).

    raw_token_info

    let raw_token_info : FormatterInfo

    Metadata of Python's RawTokenFormatter.

    rtf_formatter

    fn rtf_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's RtfFormatter. Options: style, fontface, fontsize, linenos, lineno_fontsize, lineno_padding, linenostart, linenostep, lineno_color, hl_lines, hl_color, hl_linenostart.

    rtf_info

    let rtf_info : FormatterInfo

    Metadata of Python's RtfFormatter.

    svg_formatter

    fn svg_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's SvgFormatter. Options: style, nowrap, fontfamily, fontsize, xoffset, yoffset, ystep, spacehack, linenos, linenostart, linenostep, linenowidth.

    svg_info

    let svg_info : FormatterInfo

    Metadata of Python's SvgFormatter.

    terminal256_formatter

    fn terminal256_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's Terminal256Formatter (options style, linenos, and the presence of nobold/nounderline/noitalic).

    terminal256_info

    let terminal256_info : FormatterInfo

    Metadata of Python's Terminal256Formatter.

    terminal_colors

    fn terminal_colors() -> Map[
    TokenType
    , (String, String)]

    Python's terminal.TERMINAL_COLORS: (light background, dark background) color names per token type.

    terminal_formatter

    fn terminal_formatter(options? : Map[String, String], style? :
    Style
    , colorscheme? : Map[
    TokenType
    , (String, String)]) -> Formatter raise

    Python's TerminalFormatter (options bg = light/dark, linenos; colorscheme is the colorscheme option, which cannot be given as a string). As in Python, the line counter continues across format calls.

    terminal_info

    let terminal_info : FormatterInfo

    Metadata of Python's TerminalFormatter.

    terminal_true_color_formatter

    fn terminal_true_color_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's TerminalTrueColorFormatter.

    terminal_true_color_info

    let terminal_true_color_info : FormatterInfo

    Metadata of Python's TerminalTrueColorFormatter.

    testcase_formatter

    fn testcase_formatter(options? : Map[String, String], style? :
    Style
    ) -> Formatter raise

    Python's TestcaseFormatter: a pytest test case for the token stream.

    testcase_info

    let testcase_info : FormatterInfo

    Metadata of Python's TestcaseFormatter.

    ttype_class

    fn ttype_class(t :
    TokenType
    ) -> String

    Python's _get_ttype_class (html) / _get_ttype_name (latex): the short name of the nearest standard ancestor followed by -<component> for the remaining components (Name.Builtin.Magic gives nb-Magic).

    webify

    fn webify(color : String) -> String

    Python's html.webify: a CSS color from a style color.