@fujocoded/astro-rehype-html-headings
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@fujocoded/astro-rehype-html-headings

Collects headings from a MD(X) file in an Astro environment, similar to how Astro itself does with its getHeadings() function. The headings returned by this plugin, however, also include a html properties that includes the heading rendered to HTML.

[!IMPORTANT]
This rehype plugin can only be used in Astro since it relies on the existence of the Astro frontmatter property

Sample usage

In astro.config.js:

import { astroRehypeHtmlHeadings } from "@fujocoded/astro-rehype-html-headings";

export default defineConfig({
  // ...
  integrations: [
    mdx({
      rehypePlugins: [astroRehypeHtmlHeadings],
    }),
  ],
});

In an astro file:

const chapters = await getCollection("chapters");
chapters.map(async (a) => {
  const rendered = await a.render();
  // The logged result will look like the result of the "getHeadings" Astro function,
  // but will also contain the rendered HTML
  console.log(rendered.remarkPluginFrontmatter.headings);
});

Readme

Keywords

Package Sidebar

Install

npm i @fujocoded/astro-rehype-html-headings

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

125 kB

Total Files

7

Last publish

Collaborators

  • enigmalea
  • essential.randomn3ss