/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/muyajs/lib/contentState/tocCtrl.js
29 строк
721 B
Ran Luo
chore: convert repo to pnpm monorepo (packages/desktop, muyajs, website) (#4302)
29 май 2026, 05:25
Не верифицирован
29 май 2026, 05:25
565bfcd
Код
Авторство
О чём код?
import { generateGithubSlug } from '../utils/url' const tocCtrl = (ContentState) => { ContentState.prototype.getTOC = function() { const { blocks } = this const toc = [] for (const block of blocks) { if (/^h\d$/.test(block.type)) { const { headingStyle, key, type } = block const { text } = block.children[0] const content = headingStyle === 'setext' ? text.trim() : text.replace(/^\s*#{1,6}\s{1,}/, '').trim() const lvl = +type.substring(1) const slug = key toc.push({ content, lvl, slug, githubSlug: generateGithubSlug(content) }) } } return toc } } export default tocCtrl