First x
Utility to extract the content of the first occurence of element x from HTML or Markdown
Install
$ npm install first-x # or $ yarn add -D first-x
Usage
The following HTML
and markdown
elements/syntaxt are supported
using relevant functions:
HTML
header tags (h1
,h2
,h3
, etc...) and theirmarkdown
counterpartsHTML
image tag (img
) and it'smarkdown
counterpartHTML
paragraph tag (p
) and it'smarkdown
counterpartHTML
blockquote tag (blockquote
) and it'smarkdown
counterpart
All supported elements/syntaxt have the following functions available:
from_any
- extracts content from first found occurence regardless of syntaxfrom_html
- exclusively checkshtml
from_md
(alias offrom_markdown
) - exclusively checksmarkdown
More details in Extractor class
.
const FIRST = ; // ----------------------------------------------------------------------------- // get first header text from some content const title = FIRSTheader; // ----------------------------------------------------------------------------- // extract paragraph content exclusively from markdown const description = FIRSTp; // ----------------------------------------------------------------------------- // extract image url exclusively from html const img_url = FIRSTimg; // ----------------------------------------------------------------------------- // get first found blockquote content const quote = FIRSTblockquote;
License
MIT © webmasterish