5 releases (breaking)

0.5.0 Aug 25, 2024
0.4.0 Jul 20, 2024
0.3.0 Jul 9, 2024
0.2.0 Jul 6, 2024
0.1.0 Jul 4, 2024

#105 in Value formatting

Download history 1211/week @ 2024-12-01 1808/week @ 2024-12-08 1819/week @ 2024-12-15 1069/week @ 2024-12-22 1004/week @ 2024-12-29 1735/week @ 2025-01-05 2015/week @ 2025-01-12 1694/week @ 2025-01-19 1956/week @ 2025-01-26 1612/week @ 2025-02-02 1319/week @ 2025-02-09 1435/week @ 2025-02-16 1161/week @ 2025-02-23 1111/week @ 2025-03-02 1399/week @ 2025-03-09 1219/week @ 2025-03-16

5,040 downloads per month
Used in 3 crates

MIT license

140KB
4K SLoC

pretty_yaml is a semi-tolerant and configurable YAML formatter.

Basic Usage

You can format source code string by using format_text function.

use pretty_yaml::{config::FormatOptions, format_text};

let options = FormatOptions::default();
assert_eq!("- a\n- b\n", &format_text("-  a\n-     b", &options).unwrap());

For detailed documentation of configuration, please refer to Configuration.

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

use pretty_yaml::{config::FormatOptions, format_text};

let options = FormatOptions::default();
assert!(format_text("{", &options).is_err());

Print Syntax Tree

If you have already parsed the syntax tree with yaml_parser, you can use print_tree to print it.

use pretty_yaml::{config::FormatOptions, print_tree};
use yaml_parser::{ast::{AstNode, Root}, parse};

let input = "-  a\n-     b";
let tree = parse(input).unwrap();
let root = Root::cast(tree).unwrap();

let options = FormatOptions::default();
assert_eq!("- a\n- b\n", &print_tree(&root, &options));

Dependencies

~2MB
~45K SLoC