UNPKG

@apihawk/help-center-sdk

Version:

The ApiHawk Help Center SDK

19 lines (18 loc) 580 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const cheerio = require("cheerio"); function generateTableOfContents(html) { if (typeof html !== 'string' || !html.length) { return []; } const $ = cheerio.load(html); const toc = Array.from($('h1, h2, h3, h4, h5, h6')) .map((titleTag) => ({ tag: titleTag.name, content: $(titleTag).text(), id: $(titleTag).attr('id') })) .filter((titleTag) => titleTag.content.length > 0); return toc; } exports.default = generateTableOfContents;