Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mistval/match-tags

Extract an HTML element and its children from a string
https://github.com/mistval/match-tags

Last synced: 16 days ago
JSON representation

Extract an HTML element and its children from a string

Awesome Lists containing this project

README

        

# match-tags

Extract an HTML element and its children from a string. This can make it more efficient to work with HTML parsing libraries like cheerio. You can use this module to extract only the part of the page you care about, and have the parsing library parse only that.

## Usage

```js
const extract = require('match-tags');

const html = `



Switch branches/tags







Navigate




`;

console.log(extract(html, '

'));
```

This outputs the following:

```



Navigate



```

You can also pass a third argument to the extract function, an index to begin the search from.

## About

I use this for a couple of specific applications, so it's not necessarily tested in corner cases and with bad markup. If it's not working how you expect, feel free to open an issue in the GitHub repo.