#markup-language #jinja #html #svelte #astro #vue #github

markup_fmt

Configurable HTML/Vue/Svelte/Astro/Jinja/Twig/Nunjucks/Vento formatter

17 releases (6 breaking)

0.7.0 Apr 2, 2024
0.6.0 Mar 2, 2024
0.5.1 Feb 20, 2024
0.4.1 Feb 18, 2024
0.1.1 Nov 1, 2023

#190 in Template engine

Download history 10/week @ 2023-12-29 1/week @ 2024-01-05 10/week @ 2024-01-19 37/week @ 2024-01-26 12/week @ 2024-02-02 474/week @ 2024-02-16 134/week @ 2024-02-23 269/week @ 2024-03-01 153/week @ 2024-03-08 11/week @ 2024-03-15 151/week @ 2024-03-29 40/week @ 2024-04-05

209 downloads per month

MIT license

170KB
4K SLoC

markup_fmt is a configurable HTML/Vue/Svelte/Astro/Jinja/Twig/Nunjucks/Vento formatter.

Basic Usage

You can format source code string by using format_text function.

use markup_fmt::{config::FormatOptions, format_text, Language};

let options = FormatOptions::default();
assert_eq!("<div class=\"container\"></div>\n", &format_text(
    "<div class=container></div>",
    Language::Html,
    &options,
    |_, code, _| Ok::<_, ()>(code.into()),
).unwrap());

For detailed documentation of configuration, please refer to Configuration on GitHub.

If there're syntax errors in source code, it will return [Err]:

use markup_fmt::{config::FormatOptions, format_text, FormatError, Language, SyntaxError};

let options = FormatOptions::default();
assert!(matches!(
    format_text(
        "<div>",
        Language::Html,
        &options,
        |_, code, _| Ok::<_, ()>(code.into()),
    ).unwrap_err(),
    FormatError::Syntax(SyntaxError { .. })
));

External formatter can return [Err] as well. This error will be aggregated and returned in FormatError::External:

use markup_fmt::{config::FormatOptions, format_text, FormatError, Language};

struct ExternalFormatterError;

let options = FormatOptions::default();
assert!(matches!(
    format_text(
        "<script>a</script>",
        Language::Html,
        &options,
        |_, _, _| Err(ExternalFormatterError),
    ).unwrap_err(),
    FormatError::External(ExternalFormatterError, _)
));

Dependencies

~1.3–2MB
~41K SLoC