tack 0.1.1-alpha

A minimal syntax highlighter that outputs HTML
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 2 items with examples
  • Size
  • Source code size: 9.70 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 165.43 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • allan2/tack
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • allan2

tack

crates.io Released API docs MIT licensed

Tack is a minimal syntax highlighter that outputs HTML.

Note: this library is alpha and subject to breaking API changes. More languages are on the way!

Features:

  • class-based
  • minimal HTML

Supported languages:

  • CSS

For a more fully-featured syntax highlighter, use syntect.

Examples

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

Tack usage:

fn main() {
    let s = "
body {
display: flex;
min-height: 100%;
}".to_string();

    let html = tack::coloured_html(s);
    println!("{}", html);
}

Tack output:

<span class="tag">body</span> {
  <span class="property">display</span>: <span class="string">flex</span>;
  <span class="property">min-height</span>: <span class="numeric">100%</span>;
}

syntect usage:

use syntect::{
    html::{ClassStyle, ClassedHTMLGenerator},
    parsing::SyntaxSet,
    util::LinesWithEndings,
};

fn main() {
    let ss = SyntaxSet::load_defaults_newlines();

    let s = "
body {
    display: flex;
    min-height: 100%;
}";

    let syntax_ref = ss.find_syntax_by_extension("css").unwrap();
    let mut html_generator =
        ClassedHTMLGenerator::new_with_class_style(syntax_ref, &ss, ClassStyle::Spaced);
    for line in LinesWithEndings::from(s) {
        html_generator.parse_html_for_line_which_includes_newline(line);
    }
    let html = html_generator.finalize();
    println!("{}", html);
}

syntect output:

<span class="source css">
  <span class="meta selector css"><span class="entity name tag css">body</span> </span><span
    class="meta property-list css"><span class="punctuation section property-list css">{</span>
    <span class="meta property-name css"><span class="support type property-name css">display</span></span><span
      class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span
      class="meta property-value css"><span class="support constant property-value css">flex</span></span><span
      class="punctuation terminator rule css">;</span>
    <span class="meta property-name css"><span class="support type property-name css">min-height</span></span><span
      class="punctuation separator key-value css">:</span><span class="meta property-value css"> </span><span
      class="meta property-value css"><span class="constant numeric css">100<span
          class="keyword other unit css">%</span></span></span><span class="punctuation terminator rule css">;</span>
  </span><span class="punctuation section property-list css">}</span></span>