https://github.com/webmasterish/first-x
Utility to extract the content of the first occurence of element x from HTML or Markdown
https://github.com/webmasterish/first-x
blockquote content extract header html image markdow paragraph regex utility
Last synced: about 2 months ago
JSON representation
Utility to extract the content of the first occurence of element x from HTML or Markdown
- Host: GitHub
- URL: https://github.com/webmasterish/first-x
- Owner: webmasterish
- License: mit
- Created: 2019-01-17T04:44:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-18T04:51:47.000Z (over 6 years ago)
- Last Synced: 2025-03-19T10:08:58.027Z (2 months ago)
- Topics: blockquote, content, extract, header, html, image, markdow, paragraph, regex, utility
- Language: JavaScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# First x
> Utility to extract the content of the first occurence of element x from HTML or Markdown
[](https://travis-ci.org/webmasterish/first-x)
[](http://npm.im/first-x)
[](https://greenkeeper.io/)
[](http://opensource.org/licenses/MIT)## Install
```sh
$ 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 their `markdown` counterparts
- `HTML` image tag (`img`) and it's `markdown` counterpart
- `HTML` paragraph tag (`p`) and it's `markdown` counterpart
- `HTML` blockquote tag (`blockquote`) and it's `markdown` counterpartAll supported elements/syntaxt have the following functions available:
- `from_any` - extracts content from first found occurence regardless of syntax
- `from_html` - exclusively checks `html`
- `from_md` (alias of `from_markdown`) - exclusively checks `markdown`More details in [`Extractor class`](lib/Extractor.js).
```js
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 );
```
## License
MIT © [webmasterish](https://webmasterish.com)