node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org »

posthtml-pug

npm node deps tests coverage code style chat

Pug

Parser for PostHTML

Install

npm i -D posthtml-pug

Usage

import { readFileSync } from ('fs')
 
import pug from 'posthtml-pug'
import posthtml from 'posthtml'
 
const file = readFileSync('./index.pug', 'utf8')
 
posthtml()
  .process(file, { parser: pug({ locals: {} }) })
  .then((result) => console.log(result.html))

Options

See the Pug API for a full description of the options that can be passed. By default the following options are set:

Name Default
pretty true
locals {}

Example

index.pug

doctype html
html
  head
    meta(charset="utf8")
    title Pug Parser
  body
    h1#title Pug for PostHTML
    p= greeting

import { readFileSync } from ('fs')
 
import pug from 'posthtml-pug'
import posthtml from 'posthtml'
 
const file = readFileSync('./index.pug', 'utf8')
const locals = { greeting: 'Hello!' }
 
posthtml()
  .process(file, { parser: pug({ locals: locals }) })
  .then((result) => console.log(result.html))

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Pug Parser</title>
  </head>
  <body>
    <h1 id="title">Pug for PostHTML</h1>
    <p>Hello!</p>
  </body>
</html>

Maintainer


Michael Ciniawsky

Contributors


Jeff Escalante

Timothy Gu