toc.ts — ui Source File
Architecture documentation for toc.ts, a typescript file in the ui codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 6b69cecd_f6b0_5bf0_19b4_7a9032d5992d["toc.ts"] f08a0ad4_761c_85d0_ea5b_7aad211900ce["mdast-util-toc"] 6b69cecd_f6b0_5bf0_19b4_7a9032d5992d --> f08a0ad4_761c_85d0_ea5b_7aad211900ce db43b001_743f_2d89_3f6d_76c5cb8cb209["remark"] 6b69cecd_f6b0_5bf0_19b4_7a9032d5992d --> db43b001_743f_2d89_3f6d_76c5cb8cb209 fcbb6195_57aa_1339_fa5f_694d53020f20["unist-util-visit"] 6b69cecd_f6b0_5bf0_19b4_7a9032d5992d --> fcbb6195_57aa_1339_fa5f_694d53020f20 style 6b69cecd_f6b0_5bf0_19b4_7a9032d5992d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
// @ts-nocheck
// TODO: I'll fix this later.
import { toc } from "mdast-util-toc"
import { remark } from "remark"
import { visit } from "unist-util-visit"
const textTypes = ["text", "emphasis", "strong", "inlineCode"]
function flattenNode(node) {
const p = []
visit(node, (node) => {
if (!textTypes.includes(node.type)) return
p.push(node.value)
})
return p.join(``)
}
interface Item {
title: string
url: string
items?: Item[]
}
interface Items {
items?: Item[]
}
function getItems(node, current): Items {
if (!node) {
return {}
}
if (node.type === "paragraph") {
visit(node, (item) => {
if (item.type === "link") {
current.url = item.url
current.title = flattenNode(node)
}
if (item.type === "text") {
current.title = flattenNode(node)
}
})
return current
}
if (node.type === "list") {
current.items = node.children.map((i) => getItems(i, {}))
return current
} else if (node.type === "listItem") {
const heading = getItems(node.children[0], {})
if (node.children.length > 1) {
getItems(node.children[1], heading)
}
return heading
}
return {}
}
const getToc = () => (node, file) => {
const table = toc(node)
const items = getItems(table.map, {})
file.data = items
}
export type TableOfContents = Items
export async function getTableOfContents(
content: string
): Promise<TableOfContents> {
const result = await remark().use(getToc).process(content)
return result.data
}
Domain
Subdomains
Types
Dependencies
- mdast-util-toc
- remark
- unist-util-visit
Source
Frequently Asked Questions
What does toc.ts do?
toc.ts is a source file in the ui codebase, written in typescript. It belongs to the ComponentRegistry domain, Styles subdomain.
What functions are defined in toc.ts?
toc.ts defines 4 function(s): flattenNode, getItems, getTableOfContents, getToc.
What does toc.ts depend on?
toc.ts imports 3 module(s): mdast-util-toc, remark, unist-util-visit.
Where is toc.ts in the architecture?
toc.ts is located at deprecated/www/lib/toc.ts (domain: ComponentRegistry, subdomain: Styles, directory: deprecated/www/lib).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free