Utility to extract the content of the first occurence of element x from HTML or Markdown
$ npm install first-x # or $ yarn add -D first-xThe following HTML and markdown elements/syntaxt are supported using relevant functions:
HTMLheader tags (h1,h2,h3, etc...) and theirmarkdowncounterpartsHTMLimage tag (img) and it'smarkdowncounterpartHTMLparagraph tag (p) and it'smarkdowncounterpartHTMLblockquote tag (blockquote) and it'smarkdowncounterpart
All supported elements/syntaxt have the following functions available:
from_any- extracts content from first found occurence regardless of syntaxfrom_html- exclusively checkshtmlfrom_md(alias offrom_markdown) - exclusively checksmarkdown
More details in Extractor class.
const FIRST = require('first-x'); // ----------------------------------------------------------------------------- // get first header text from some content const title = FIRST.header.from_any( content ); // ----------------------------------------------------------------------------- // extract paragraph content exclusively from markdown const description = FIRST.p.from_md( content ); // ----------------------------------------------------------------------------- // extract image url exclusively from html const img_url = FIRST.img.from_html( content ); // ----------------------------------------------------------------------------- // get first found blockquote content const quote = FIRST.blockquote.from_any( content );MIT © webmasterish