Crates.io | markup_fmt |
lib.rs | markup_fmt |
version | 0.18.0 |
source | src |
created_at | 2023-11-01 10:28:09.415787 |
updated_at | 2024-12-02 13:34:26.184585 |
description | Configurable HTML, Vue, Svelte, Astro, Angular, Jinja, Twig, Nunjucks and Vento formatter. |
homepage | |
repository | https://github.com/g-plane/markup_fmt |
max_upload_size | |
id | 1020830 |
size | 247,421 |
markup_fmt is a configurable HTML, Vue, Svelte, Astro, Angular, Jinja, Twig, Nunjucks and Vento formatter.
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::<_, std::convert::Infallible>(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::<_, std::convert::Infallible>(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(errors) if !errors.is_empty()
));