Giter Club home page Giter Club logo

marko-prettyprint's Introduction

marko-prettyprint

Prettyprint Marko template files in the syntax and with the options of your choice.

Installation

Global install of the command line utility:

npm install marko-prettyprint --global

Local project install:

npm install marko-prettyprint --save

Usage

Pretty print a single file from the command line

marko-prettyprint template.marko --syntax html

Pretty print a directory tree from the command line

marko-prettyprint . --syntax html

Pretty print a file in a Node.js app

var prettyPrintFile = require('marko-prettyprint').prettyPrintFile;

var templatePath = require('path').join(__dirname, 'template.marko');
var options = {
    syntax: 'html'
};

var prettySrc = prettyPrintFile(templatePath, options);

Options

  • eol - The EOL sequence (defaults to require('os').EOL)
  • filename - The path to the template being pretty printed (required unless prettyPrintFile(filename, options) is used)
  • indent - The indent string (defaults to a String with four spaces)
  • maxLen - The max line length (defaults to 80, set to -1 to disable)
  • configFiles - Should search for .marko-prettyprint/.editorconfig files? (defaults to true)
  • syntax - The syntax to use. Can either be "html" or "concise" (defaults to "html")

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

API

JavaScript API

require('marko-prettyprint')

prettyPrintSource(src, options)

prettyPrintFile(filename, options)

prettyPrintAST(ast, options)

Command Line

To recursively prettyprint all Marko v3 templates in a directory to use the HTML syntax:

marko-prettyprint . --syntax html

To recursively prettyprint all Marko v3 templates in a directory to use the HTML syntax:

marko-prettyprint . --syntax concise

Individual files and directories can also be prettyprinted:

marko-prettyprint src/ foo/
marko-prettyprint template1.marko template2.marko

The maximum line length (defaults to 80) can be also be set:

marko-prettyprint . --syntax html --max-len 120

marko-prettyprint's People

Contributors

patrick-steele-idem avatar austinkelleher avatar greenkeeper[bot] avatar yomed avatar garajo avatar

Watchers

James Cloos avatar Dylan Piercey avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.