getblocks
Parses files for specific blocks and returns the lines inside of them
Install
npm install getblocks
Examples
Default options & read from file path
This example will read a file from the given path, and return any fenced blocks it finds.
var getblocks = ; getblocks;
Input:
<!-- block:first --><!-- endblock --> <!-- block:second --><!-- endblock -->
Output:
first: start: 2 end: 6 content: ' <script src="aaa.js"></script>' ' <script src="bbb.js"></script>' ' <script>' ' // This is an inline script' ' </script>' second: start: 10 end: 14 content: ' <script>' ' // An additional inline script' ' </script>' ' <script src="ccc.js"></script>' ' <script src="ddd.js"></script>'
Custom options & passed content (instead of reading a file)
This example will read a file from the given path, and return any fenced blocks it finds.
var getblocks = ; getblocks;
Input:
#@ foo:first @##@ bar @# #@ foo:second @##@ bar @#
Output:
first: start: 2 end: 6 content: '<script src="aaa.js"></script>' '<script src="bbb.js"></script>' '<script>' '// This is an inline script' '</script>' second: start: 10 end: 14 content: '<script>' '// An additional inline script' '</script>' '<script src="ccc.js"></script>' '<script src="ddd.js"></script>'
API
find(options)
options.path
Type: String
If a path is set, getblocks will read a file from the given path and use that to parse content. You can either use options.path
or options.content
, but not both.
options.content
Type: String
If the content parameter is filled in, getblocks will parse that content. You can either use options.path
or options.content
, but not both.
options.startTag
Type: String
Default: '<!--'
The starting tag of a block definition.
options.endTag
Type: String
Default: '-->'
The ending tag of a block definition.
options.startKeyword
Type: String
Default: 'block'
The keyword of a block start definition.
options.endKeyword
Type: String
Default: 'endblock'
The keyword of a block end definition.
options.trimmed
Type: Boolean
Default: false
If set to true, getblocks will trim all excess whitespace (i.e. indentation) before returning the output.
License
MIT © Thomas Tuts