1.0.7 • Published 1 year ago

@hbsnow/rehype-sectionize v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

rehype-sectionize

test workflow codecov

Motivation

There is already rehype-section in the library for sectioning. But it could not change the class of section. In addition, sections could not have the slug of heading in the data attribute. I was referred rehype-section. Thanks.

Install

npm i -D @hbsnow/rehype-sectionize

Sample

Input

<h1 id="h1-id">h1</h1>
<h2 id="h2-id">h2</h2>
<h3 id="h3-id">h3</h3>

Output

<section class="heading" data-heading-rank="1" aria-labelledby="h1-id">
  <h1 id="h1-id">h1</h1>
  <section class="heading" data-heading-rank="2" aria-labelledby="h2-id">
    <h2 id="h2-id">h2</h2>
    <section class="heading" data-heading-rank="3" aria-labelledby="h3-id">
      <h3 id="h3-id">h3</h3>
    </section>
  </section>
</section>

Options

optiontypedefaultdescription
propertieshastscript.Properties{}Attributes assigned to section
enableRootSectionbooleanfalseSection to wrap all
rankPropertyNamestringdataHeadingRankName of rank data attribute
idPropertyNamestringariaLabelledbyName of id data attribute

License

MIT © hbsnow