3.6.1 • Published 5 years ago

pug-code-block v3.6.1

Weekly downloads
162
License
ISC
Repository
github
Last release
5 years ago

Pug code block

Get Pug code at and inside a given line or query.

doc.pug

doctype html
html
  head
    title my pug template
  body
    h1 Hello #{name}
    p foo

Get block at line number

Will return a string for a single match, an array of code blocks for multiple matches.

const source = fs.readFileSync('./doc.pug', 'utf8');

const getCodeBlock = require('pug-code-block');
getCodeBlock.byLine(source, 2);

// head
//   title my pug template

Optionally provide a limit of blocks to be captured. Default limit is 1. Use Infinity if you want to capture all blocks.

const source = fs.readFileSync('./doc.pug', 'utf8');

const getCodeBlock = require('pug-code-block');
getCodeBlock.byLine(source, 1, 3);

// div yep
// div yep
// div yep
// div nope
// div nope

Get block at string match

Will return a string for a single match, an array of code blocks for multiple matches. Arguments can be a string or regex.

const source = fs.readFileSync('./doc.pug', 'utf8');

const getCodeBlock = require('pug-code-block');
getCodeBlock.byString(source, 'body');

// body
//   h1 Hello #{name}
//   p foo
const source = fs.readFileSync('./doc.pug', 'utf8');

const getCodeBlock = require('pug-code-block');
getCodeBlock.byString(source, /body/);

// body
//   h1 Hello #{name}
//   p foo
3.6.1

5 years ago

3.6.0

6 years ago

3.5.0

9 years ago

3.4.0

10 years ago

3.3.0

10 years ago

3.2.0

10 years ago

3.1.0

10 years ago

3.0.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.3.0

10 years ago