From 660aae62e09ea1f5ec957149b78bfd01a85bd79f Mon Sep 17 00:00:00 2001
From: Odaimoko <934854676@qq.com>
Date: Tue, 28 Nov 2023 07:05:18 +0000
Subject: [PATCH] docs: add Imk&Cc's homepage to showcase.md (#595)
---
quartz/plugins/transformers/ofm.ts | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts
index 226e939..2e47ced 100644
--- a/quartz/plugins/transformers/ofm.ts
+++ b/quartz/plugins/transformers/ofm.ts
@@ -1,7 +1,7 @@
import { PluggableList } from "unified"
import { QuartzTransformerPlugin } from "../types"
import { Root, HTML, BlockContent, DefinitionContent, Code, Paragraph } from "mdast"
-import { Element, Literal } from "hast"
+import { Element, Literal, Root as HtmlRoot } from "hast"
import { Replace, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
import { slug as slugAnchor } from "github-slugger"
import rehypeRaw from "rehype-raw"
@@ -110,7 +110,10 @@
// ([^\[\]\|\#]+) -> one or more non-special characters ([,],|, or #) (name)
// (#[^\[\]\|\#]+)? -> # then one or more non-special characters (heading link)
// (|[^\[\]\|\#]+)? -> | then one or more non-special characters (alias)
-const wikilinkRegex = new RegExp(/!?\[\[([^\[\]\|\#]+)?(#[^\[\]\|\#]+)?(\|[^\[\]\|\#]+)?\]\]/, "g")
+export const wikilinkRegex = new RegExp(
+ /!?\[\[([^\[\]\|\#]+)?(#+[^\[\]\|\#]+)?(\|[^\[\]\|\#]+)?\]\]/,
+ "g",
+)
const highlightRegex = new RegExp(/==([^=]+)==/, "g")
const commentRegex = new RegExp(/%%(.+)%%/, "g")
// from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts
@@ -178,7 +181,7 @@
src = src.replaceAll(wikilinkRegex, (value, ...capture) => {
const [rawFp, rawHeader, rawAlias] = capture
const fp = rawFp ?? ""
- const anchor = rawHeader?.trim().slice(1)
+ const anchor = rawHeader?.trim().replace(/^#+/, "")
const displayAnchor = anchor ? `#${slugAnchor(anchor)}` : ""
const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? ""
const embedDisplay = value.startsWith("!") ? "!" : ""
@@ -236,13 +239,13 @@
value: `<iframe src="${url}"></iframe>`,
}
} else if (ext === "") {
- const block = anchor.slice(1)
+ const block = anchor
return {
type: "html",
data: { hProperties: { transclude: true } },
value: `<blockquote class="transclude" data-url="${url}" data-block="${block}"><a href="${
url + anchor
- }" class="transclude-inner">Transclude of block ${block}</a></blockquote>`,
+ }" class="transclude-inner">Transclude of ${url}${block}</a></blockquote>`,
}
}
@@ -477,6 +480,8 @@
}
}
})
+
+ file.data.htmlAst = tree
}
})
}
@@ -524,5 +529,6 @@
declare module "vfile" {
interface DataMap {
blocks: Record<string, Element>
+ htmlAst: HtmlRoot
}
}
--
Gitblit v1.10.0