Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
fix(docz-utils): extract headings from ast
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jan 21, 2019
1 parent 54ad0fa commit 9f8565b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions core/docz-utils/src/mdast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ const valueFromHeading = (node: any) => {
return humanize(slug)
}

const extractAst = <T>(callback: (node: any) => T, type: string) => {
return (ast: any): T[] => {
function extractAst<T>(
callback: (node: any) => T,
type: string
): (ast: any) => T[] {
return ast => {
const results: T[] = []

visit(ast, type, (node: any) => {
Expand All @@ -58,11 +61,14 @@ export interface Heading {
value: string
}

export const headingsFromAst = extractAst<Heading>((node: any) => ({
depth: get(node, 'data.id'),
slug: get(node, 'depth'),
value: valueFromHeading(node),
}), 'heading')
export const headingsFromAst = extractAst<Heading>(
(node: any) => ({
slug: get(node, 'data.id'),
depth: get(node, 'depth'),
value: valueFromHeading(node),
}),
'heading'
)

export interface ParsedData {
[key: string]: any
Expand Down

0 comments on commit 9f8565b

Please sign in to comment.