Skip to content

Instantly share code, notes, and snippets.

@Pixlox
Created November 7, 2024 06:47
Show Gist options
  • Save Pixlox/4a1fa355a4ed2dc2cfb266d10bd46704 to your computer and use it in GitHub Desktop.
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.
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
@Pixlox
Copy link
Author

Pixlox commented Nov 7, 2024

To use this:

  1. add the file into /plugins/transformers/
  2. add export { Furigana } from "./furigana" to /plugins/transformers/index.ts
  3. in your quartz.config.ts, add Plugin.Furigana() into your transformers section.

image

Super clean and simple :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment