Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get catalog #33

Closed
WinmezzZ opened this issue Feb 25, 2021 · 1 comment
Closed

How to get catalog #33

WinmezzZ opened this issue Feb 25, 2021 · 1 comment

Comments

@WinmezzZ
Copy link

Any get catalog api had been exported? I saw catelog in editor toolbar, but how can I get catalog without editor? Just like in a post detail page.

My html string get by getProcessor api, it imported from bytemd, so I want to ask that did you exported get catelog api like getProcessor.

Thanks.

@pd4d10
Copy link
Owner

pd4d10 commented Feb 27, 2021

The TOC is extracted from the hast syntax tree:

import { getProcessor } from 'bytemd'

let hast
getProcessor({
  plugins: [
    {
      rehype: (p) =>
        p.use(() => (tree) => {
          hast = tree
        }),
    },
  ],
}).processSync(value);

console.log(hast) // h1-h6 is what you want

@WinmezzZ WinmezzZ closed this as completed Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants