From 5b90fbd0d0ac93a6ef5921f7693d36574224531c Mon Sep 17 00:00:00 2001
From: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
Date: Sun, 04 Feb 2024 05:51:55 +0000
Subject: [PATCH] feat(ofm): parsing all type of arrow (#797)
---
quartz/plugins/transformers/ofm.ts | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts
index 44df3fa..18ff6b4 100644
--- a/quartz/plugins/transformers/ofm.ts
+++ b/quartz/plugins/transformers/ofm.ts
@@ -74,6 +74,17 @@
cite: "quote",
} as const
+const arrowMapping: Record<string, string> = {
+ "->": "→",
+ "-->": "⇒",
+ "=>": "⇒",
+ "==>": "⇒",
+ "<-": "←",
+ "<--": "⇐",
+ "<=": "⇐",
+ "<==": "⇐",
+}
+
function canonicalizeCallout(calloutName: string): keyof typeof calloutMapping {
const normalizedCallout = calloutName.toLowerCase() as keyof typeof calloutMapping
// if callout is not recognized, make it a custom one
@@ -82,7 +93,7 @@
export const externalLinkRegex = /^https?:\/\//i
-export const arrowRegex = new RegExp(/-{1,2}>/, "g")
+export const arrowRegex = new RegExp(/(-{1,2}>|={1,2}>|<-{1,2}|<={1,2})/, "g")
// !? -> optional embedding
// \[\[ -> open brace
@@ -271,10 +282,12 @@
if (opts.parseArrows) {
replacements.push([
arrowRegex,
- (_value: string, ..._capture: string[]) => {
+ (value: string, ..._capture: string[]) => {
+ const maybeArrow = arrowMapping[value]
+ if (maybeArrow === undefined) return SKIP
return {
type: "html",
- value: `<span>→</span>`,
+ value: `<span>${maybeArrow}</span>`,
}
},
])
--
Gitblit v1.10.0