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

#48 in Value formatting

Download history 1045/week @ 2024-08-21 778/week @ 2024-08-28 1320/week @ 2024-09-04 929/week @ 2024-09-11 884/week @ 2024-09-18 897/week @ 2024-09-25 1272/week @ 2024-10-02 2094/week @ 2024-10-09 1465/week @ 2024-10-16 2147/week @ 2024-10-23 1375/week @ 2024-10-30 1307/week @ 2024-11-06 1022/week @ 2024-11-13 1288/week @ 2024-11-20 1395/week @ 2024-11-27 1108/week @ 2024-12-04

4,982 downloads per month
Used in 5 crates (4 directly)

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
~34K SLoC