From ef72f1bf707dca363cdab84da91e2acfaef8f276 Mon Sep 17 00:00:00 2001
From: Ammar Alakkad <am.alakkad@gmail.com>
Date: Mon, 30 Dec 2024 16:03:57 +0000
Subject: [PATCH] Fix ObsidianFlavoredMarkdown source link (#1694)
---
quartz/processors/parse.ts | 43 +++++++++++++++++++++----------------------
1 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/quartz/processors/parse.ts b/quartz/processors/parse.ts
index 29f92fc..2bd530c 100644
--- a/quartz/processors/parse.ts
+++ b/quartz/processors/parse.ts
@@ -14,27 +14,25 @@
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,12 +87,13 @@
// 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
- file.data.slug = slugifyFilePath(path.posix.relative(argv.directory, file.path) as FilePath)
- file.data.filePath = fp
+ file.data.filePath = file.path as FilePath
+ file.data.relativePath = path.posix.relative(argv.directory, file.path) as FilePath
+ file.data.slug = slugifyFilePath(file.data.relativePath)
const ast = processor.parse(file)
const newAst = await processor.run(ast, file)
@@ -144,7 +143,7 @@
const childPromises: WorkerPromise<ProcessedContent[]>[] = []
for (const chunk of chunks(fps, CHUNK_SIZE)) {
- childPromises.push(pool.exec("parseFiles", [argv, chunk, ctx.allSlugs]))
+ childPromises.push(pool.exec("parseFiles", [ctx.buildId, argv, chunk, ctx.allSlugs]))
}
const results: ProcessedContent[][] = await WorkerPromise.all(childPromises).catch((err) => {
--
Gitblit v1.10.0