Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/agentofuser/rehype-section

Wraps headings and their contents in `<section>` elements.
https://github.com/agentofuser/rehype-section

rehype rehype-plugin typescript typescript-library unist

Last synced: 7 days ago
JSON representation

Wraps headings and their contents in `<section>` elements.

Awesome Lists containing this project

README

        

# rehype-section

[![Downloads][downloads-badge]][downloads] [![Chat][chat-badge]][chat]

Wraps headings and their contents in `` elements.

## Installation

[npm][]:

```bash
npm install @agentofuser/rehype-section
```

## Usage

Say we have the following file, `fragment.html`:

```html

h1


h2a


h3ai


text3ai


h3aj


text3aj


h2b


h3bi


h4bix


text4bix


h2c


h3ci


text3ci


```

And our script, `example.js`, looks as follows:

```javascript
var fs = require('fs')
var rehype = require('rehype')
var section = require('rehype-section')

rehype()
.data('settings', { fragment: true })
.use(section)
.process(fs.readFileSync('fragment.html'), function(err, file) {
if (err) throw err
console.log(String(file))
})
```

Now, running `node example` yields:

```html


h1



h2a



h3ai


text3ai




h3aj


text3aj





h2b



h3bi



h4bix


text4bix






h2c



h3ci


text3ci




```

## API

### `rehype().use(section)`

Wraps headings and their contents in `` elements.

## Contribute

See [`contributing.md` in `rehypejs/rehype`][contribute] for ways to get
started.

This organisation has a [Code of Conduct][coc]. By interacting with this
repository, organisation, or community you agree to abide by its terms.

## License

[MIT][license] © [Agent of User][author]

[build-badge]: https://img.shields.io/travis/agentofuser/rehype-section.svg
[build]: https://travis-ci.org/agentofuser/rehype-section
[downloads-badge]: https://img.shields.io/npm/dm/rehype-section.svg
[downloads]: https://www.npmjs.com/package/@agentofuser/rehype-section
[chat-badge]:
https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
[chat]: https://spectrum.chat/unified/rehype
[npm]: https://docs.npmjs.com/cli/install
[license]: license
[author]: https://agentofuser.com
[rehype]: https://github.com/rehypejs/rehype
[contribute]: https://github.com/rehypejs/rehype/blob/master/contributing.md
[coc]: https://github.com/rehypejs/rehype/blob/master/code-of-conduct.md