An XML formatter written in MoonBit, ported from python xmlformatter.
Dependencies
moon add kupas/xmlfmtmoon install kupas/xmlfmt/cmd/xmlfmtcurl -LsSf https://raw.githubusercontent.com/tomasky/xmlfmt/main/install.sh | bashnpm install -g @tomasko/xmlfmt
# or
pnpm install -g @tomasko/xmlfmtimport "kupas/xmlfmt"
fn main {
let xml = "<root><child>text</child></root>"
let result = @xmlfmt.format(xml, @xmlfmt.default_options())
println(result)
}moon install kupas/xmlfmt/cmd/xmlfmt
xmlfmt input.xml
xmlfmt --compress input.xml
xmlfmt --indent 4 input.xml| Option | Short | Default | Description |
|---|---|---|---|
| --indent <num> | -i | 2 | Number of indent characters per level |
| --indent-char <char> | -I | space | Indentation character |
| --compress | -c | false | Minify output: remove all unnecessary whitespace, single line |
| --selfclose | -s | false | Use self-closing tags for empty elements (<empty/>) |
| --selfclose-space | -S | false | Add space before /> (<empty />) |
| --disable-inlineformatting | -l | false | Disable inline formatting (see below) |
| --disable-correction | -C | false | Disable whitespace correction |
| --blanks | -b | false | Preserve blank lines (collapse multiple into one) |
| --eof-newline | -n | false | Add newline at end of file |
| --preserve <elems> | -p | none | Comma-separated elements to preserve whitespace in |
| --preserve-attributes | -a | false | Preserve original attribute order (default: sort) |
| --encode-attributes | -E | false | Encode > and ' in attribute values |
| --output <file> | -o | none | Write output to file |
| --infile <file> | -f | none | Input file |
| --overwrite | -w | false | Overwrite input file in place |
<root>
<child>text</child>
<nested>
<deep>value</deep>
</nested>
</root><!-- default (inline) -->
<root>
<name>John</name>
<items>
<item>1</item>
<item>2</item>
</items>
</root>
<!-- with -l (disabled inline) -->
<root>
<name>
John
</name>
<items>
<item>
1
</item>
</items>
</root><!-- input: <root><empty></empty></root> -->
<!-- output: <root><empty/></root> -->xmlfmt -p "pre,code,script" input.xmlpub(all) struct XmlOptions {
indent : Int
indent_char : String
compress : Bool
selfclose : Bool
selfclose_space : Bool
inline : Bool
correct : Bool
blanks : Bool
eof_newline : Bool
preserve : Array[String]
preserve_attributes : Bool
encode_attributes : Bool
}Install
Download zipAn XML formatter written in MoonBit, ported from python xmlformatter.
Dependencies