pretty_yaml

Crates.iopretty_yaml
lib.rspretty_yaml
version0.5.0
sourcesrc
created_at2024-07-04 08:07:08.991972
updated_at2024-08-25 10:25:02.939448
descriptionSemi-tolerant and configurable YAML formatter.
homepage
repositoryhttps://github.com/g-plane/pretty_yaml
max_upload_size
id1291407
size69,799
Pig Fang (g-plane)

documentation

README

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));
Commit count: 200

cargo fmt