Created
November 7, 2024 06:47
-
-
Save Pixlox/4a1fa355a4ed2dc2cfb266d10bd46704 to your computer and use it in GitHub Desktop.
A transformer for Quartz that adds furigana support. A companion to obsidian-markdown-furigana.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { QuartzTransformerPlugin } from "../types" | |
import { findAndReplace } from "mdast-util-find-and-replace" | |
export const Furigana: QuartzTransformerPlugin = () => { | |
return { | |
name: "Furigana", | |
markdownPlugins() { | |
return [ | |
() => { | |
return (tree, _file) => { | |
// Match pattern {base|furigana} | |
findAndReplace(tree, /\{([^\|]+)\|([^\}]+)\}/g, (_value: string, ...capture: string[]) => { | |
const [baseText, furiganaText] = capture | |
return { | |
type: "html", | |
value: `<ruby>${baseText}<rt>${furiganaText}</rt></ruby>` | |
} | |
}) | |
} | |
} | |
] | |
} | |
} | |
} | |
export default Furigana |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this:
/plugins/transformers/
export { Furigana } from "./furigana"
to/plugins/transformers/index.ts
quartz.config.ts
, addPlugin.Furigana()
into your transformers section.Super clean and simple :)