From fa6c02d3213dfd4e6da8e78bd3a2e7004555fd01 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Wed, 24 Jan 2024 01:08:56 +0000
Subject: [PATCH] fix: make search result card block
---
quartz/plugins/transformers/ofm.ts | 25 +++++++++++--------------
1 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts
index e1f7651..c067296 100644
--- a/quartz/plugins/transformers/ofm.ts
+++ b/quartz/plugins/transformers/ofm.ts
@@ -1,5 +1,5 @@
import { QuartzTransformerPlugin } from "../types"
-import { Root, Html, Image, BlockContent, DefinitionContent, Paragraph, Code } from "mdast"
+import { Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast"
import { Element, Literal, Root as HtmlRoot } from "hast"
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
import { slug as slugAnchor } from "github-slugger"
@@ -125,7 +125,7 @@
"g",
)
const highlightRegex = new RegExp(/==([^=]+)==/, "g")
-const commentRegex = new RegExp(/%%(.+)%%/, "g")
+const commentRegex = new RegExp(/%%[\s\S]*?%%/, "g")
// from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts
const calloutRegex = new RegExp(/^\[\!(\w+)\]([+-]?)/)
const calloutLineRegex = new RegExp(/^> *\[\!\w+\][+-]?.*$/, "gm")
@@ -151,6 +151,15 @@
return {
name: "ObsidianFlavoredMarkdown",
textTransform(_ctx, src) {
+ // do comments at text level
+ if (opts.comments) {
+ if (src instanceof Buffer) {
+ src = src.toString()
+ }
+
+ src = src.replace(commentRegex, "")
+ }
+
// pre-transform blockquotes
if (opts.callouts) {
if (src instanceof Buffer) {
@@ -286,18 +295,6 @@
])
}
- if (opts.comments) {
- replacements.push([
- commentRegex,
- (_value: string, ..._capture: string[]) => {
- return {
- type: "text",
- value: "",
- }
- },
- ])
- }
-
if (opts.parseArrows) {
replacements.push([
arrowRegex,
--
Gitblit v1.10.0