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

Commit

Permalink
fix(docz-core): apply mdast plugins to entries parse too
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jan 21, 2019
1 parent 3e453f5 commit c2554b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/docz-core/src/lib/Entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Entries {
}

private async getMap(config: Config): Promise<EntryMap> {
const { src, files: pattern, ignore, plugins } = config
const { src, files: pattern, ignore, plugins, mdPlugins } = config
const arr = Array.isArray(pattern) ? pattern : [pattern]
const toMatch = matchFilesWithSrc(config)

Expand All @@ -90,7 +90,7 @@ export class Entries {

const createEntry = async (file: string) => {
try {
const ast = await parseMdx(file)
const ast = await parseMdx(file, mdPlugins)
const entry = new Entry(ast, file, src, config)

if (this.repoEditUrl) entry.setLink(this.repoEditUrl)
Expand Down
7 changes: 6 additions & 1 deletion core/docz-utils/src/mdast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ import humanize from 'humanize-string'
import flatten from 'lodash.flatten'
import get from 'lodash.get'

export const parseMdx = (file: string): Promise<string> => {
export const parseMdx = (file: string, plugins: any[]): Promise<string> => {
const raw = vfile.readSync(file, 'utf-8')
const parser = unified()
.use(remark, { type: 'yaml', marker: '-' })
.use(matter)
.use(parseFrontmatter)
.use(slug)

for (const plugin of plugins) {
const [item, opts = {}] = Array.isArray(plugin) ? plugin : [plugin]
parser.use(item, opts)
}

return parser.run(parser.parse(raw))
}

Expand Down

0 comments on commit c2554b8

Please sign in to comment.