mirror of
https://github.com/alrayyes/wiki.git
synced 2025-05-02 23:08:14 +00:00
* deps: bump ws * deps: bump lightningcss * deps: workerpool * deps: various types * deps: chalk * deps: globby * deps: preact * deps: tsx * deps: @floating-ui/dom * deps: esbuild * deps: types + prettier * deps: rimraf, typescript * deps: remark/rehype/unified ecosystem * format
This commit is contained in:
parent
78b33fc2fb
commit
ea6208c1f0
14 changed files with 2329 additions and 1891 deletions
quartz/processors
|
@ -14,27 +14,25 @@ import { QuartzLogger } from "../util/log"
|
|||
import { trace } from "../util/trace"
|
||||
import { BuildCtx } from "../util/ctx"
|
||||
|
||||
export type QuartzProcessor = Processor<MDRoot, HTMLRoot, void>
|
||||
export type QuartzProcessor = Processor<MDRoot, MDRoot, HTMLRoot>
|
||||
export function createProcessor(ctx: BuildCtx): QuartzProcessor {
|
||||
const transformers = ctx.cfg.plugins.transformers
|
||||
|
||||
// base Markdown -> MD AST
|
||||
let processor = unified().use(remarkParse)
|
||||
|
||||
// MD AST -> MD AST transforms
|
||||
for (const plugin of transformers.filter((p) => p.markdownPlugins)) {
|
||||
processor = processor.use(plugin.markdownPlugins!(ctx))
|
||||
}
|
||||
|
||||
// MD AST -> HTML AST
|
||||
processor = processor.use(remarkRehype, { allowDangerousHtml: true })
|
||||
|
||||
// HTML AST -> HTML AST transforms
|
||||
for (const plugin of transformers.filter((p) => p.htmlPlugins)) {
|
||||
processor = processor.use(plugin.htmlPlugins!(ctx))
|
||||
}
|
||||
|
||||
return processor
|
||||
return (
|
||||
unified()
|
||||
// base Markdown -> MD AST
|
||||
.use(remarkParse)
|
||||
// MD AST -> MD AST transforms
|
||||
.use(
|
||||
transformers
|
||||
.filter((p) => p.markdownPlugins)
|
||||
.flatMap((plugin) => plugin.markdownPlugins!(ctx)),
|
||||
)
|
||||
// MD AST -> HTML AST
|
||||
.use(remarkRehype, { allowDangerousHtml: true })
|
||||
// HTML AST -> HTML AST transforms
|
||||
.use(transformers.filter((p) => p.htmlPlugins).flatMap((plugin) => plugin.htmlPlugins!(ctx)))
|
||||
)
|
||||
}
|
||||
|
||||
function* chunks<T>(arr: T[], n: number) {
|
||||
|
@ -89,7 +87,7 @@ export function createFileParser(ctx: BuildCtx, fps: FilePath[]) {
|
|||
|
||||
// Text -> Text transforms
|
||||
for (const plugin of cfg.plugins.transformers.filter((p) => p.textTransform)) {
|
||||
file.value = plugin.textTransform!(ctx, file.value)
|
||||
file.value = plugin.textTransform!(ctx, file.value.toString())
|
||||
}
|
||||
|
||||
// base data properties that plugins may use
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue