@marko/prettyprint
Prettyprint Marko template files in the syntax of your choice.
CLI
Getting Started
npm install @marko/prettyprint
marko-prettyprint template.marko
or
npx @marko/prettyprint template.marko
Example
# Pretty print a single file.
marko-prettyprint template.marko --syntax html
# Pretty print all Marko files in a directory.
marko-prettyprint . --syntax html
Options
--eol: The EOL sequence (defaults torequire('os').EOL)--filename: The path to the template being pretty printed (required unlessprettyPrintFile(filename, options)is used)--indent: The indent string (defaults to aStringwith four spaces)--noSemi: If set, will format JS without semicolons.--singleQuote: If set, will prefer single quotes.--maxLen: The max line length (defaults to80, set to-1to disable)--configFiles: Should search for.marko-prettyprint/.editorconfigfiles? (defaults totrue)--syntax: The syntax to use. Can either be"html"or"concise"(defaults to"html")
API
Installation
npm install @marko/prettyprint
Example
import {
prettyPrintFile,
prettyPrintSource,
prettyPrintAST
} from "@marko/prettyprint";
prettyPrintFile("./path-to-marko-file", options) // -> Output Marko file string.
prettyPrintSource("<div x=1/>", options) // -> Output Marko file string.
const ast = compiler.parseRaw(...);
prettyPrintAST(ast, options) // -> Output Marko file string.
Configuration files
.marko-prettyprint config file
When pretty printing a Marko template, @marko/prettyprint will search up the directory tree looking for a .marko-prettyprint file. This file should be in the JSON format. For example:
my-project/.marko-prettyprint:
{
"indent": "\t",
"syntax": "concise"
}
.editorconfig file
@marko/prettyprint also supports EditorConfig files for configuring maxLen, indent and eol. For example:
my-project/.editorconfig:
root = true
[*.marko]
indent_style = space
indent_size = 8
end_of_line = lf