From 5ec61468d5e787b3c8ae32a2b4ef1595cf0bc3ee Mon Sep 17 00:00:00 2001
From: Emile Bangma <ewjbangma@hotmail.com>
Date: Sun, 31 Mar 2024 16:44:50 +0000
Subject: [PATCH] fix(wikilinks): proper escaping of pipe character in wikilinks inside tables (#1040)
---
quartz/plugins/transformers/syntax.ts | 49 +++++++++++++++++++++++++++----------------------
1 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/quartz/plugins/transformers/syntax.ts b/quartz/plugins/transformers/syntax.ts
index f09daaa..f11734e 100644
--- a/quartz/plugins/transformers/syntax.ts
+++ b/quartz/plugins/transformers/syntax.ts
@@ -1,28 +1,33 @@
-import { PluggableList } from "unified"
import { QuartzTransformerPlugin } from "../types"
-import rehypePrettyCode, { Options as CodeOptions } from "rehype-pretty-code"
+import rehypePrettyCode, { Options as CodeOptions, Theme as CodeTheme } from "rehype-pretty-code"
-export class SyntaxHighlighting extends QuartzTransformerPlugin {
- name = "SyntaxHighlighting"
+interface Theme extends Record<string, CodeTheme> {
+ light: CodeTheme
+ dark: CodeTheme
+}
- markdownPlugins(): PluggableList {
- return []
- }
+interface Options {
+ theme?: Theme
+ keepBackground?: boolean
+}
- htmlPlugins(): PluggableList {
- return [[rehypePrettyCode, {
- theme: 'css-variables',
- onVisitLine(node) {
- if (node.children.length === 0) {
- node.children = [{ type: 'text', value: ' ' }]
- }
- },
- onVisitHighlightedLine(node) {
- node.properties.className.push('highlighted')
- },
- onVisitHighlightedWord(node) {
- node.properties.className = ['word']
- },
- } satisfies Partial<CodeOptions>]]
+const defaultOptions: Options = {
+ theme: {
+ light: "github-light",
+ dark: "github-dark",
+ },
+ keepBackground: false,
+}
+
+export const SyntaxHighlighting: QuartzTransformerPlugin<Options> = (
+ userOpts?: Partial<Options>,
+) => {
+ const opts: Partial<CodeOptions> = { ...defaultOptions, ...userOpts }
+
+ return {
+ name: "SyntaxHighlighting",
+ htmlPlugins() {
+ return [[rehypePrettyCode, opts]]
+ },
}
}
--
Gitblit v1.10.0