A command line tool to extract a paragraph from a markdown content.
cat README.md | md-extract <what>
Run the following commands to download and install the application:
npm i markdown-extract -g
It also provide an api which provides more options than the binary interface.
var mdExtract = require('markdown-extract')
mdExtract ({type: /heading/, text: /Usage/, gnp: true}).join('\n')
See more in the test suite and it s markdown version.
It exposes an unique function, with three signatures
mdExtract (what[, markedOpt[, text]])
mdExtract (what, markedOpt)
mdExtract (what, text)
- what: The lookup object, regexp, or string
- markedOpt: The options passed to
marked
, default to{gfm:true}
- text: The markdown text to parse, it not provided it will fallback to
README.md
file oncwd
This function parses the markdown content, searching for nodes that matches your criterions.
It will return only their text, as an array of string, in order of appearance in the file.
- if it s a
string
or aregexp
, it selects nodes with matching type or text property - if it s an
array of string
, it selects nodes of those types - if it s a
number
, it selects nodes with given depth - if it s an
object
, then it can havetype
/text
/depth
properties with values that matches above logic. - if it s an
object
, and it s have a property (grepNextParagraph
||gnp
)==true
, then, the search is made based onheading
nodes, the results is all the followingtext
node of each matchedheading
.
The last option is the most interesting to me as you can match a heading
such ## Usage
,
but gets only it s following text
.
mdExtract ({type: /heading/, text: /Usage/, gnp: true}).join('\n')
- File an issue in the repository, using the bug tracker, describing the contribution you'd like to make. This will help us to get you started on the right foot.
- Fork the project in your account and create a new branch:
your-great-feature
. - Commit your changes in that branch.
- Open a pull request, and reference the initial issue in the pull request message.
WTF.