From 65994f81a4bb1d3fbe525de2e56ce410a20856d9 Mon Sep 17 00:00:00 2001 From: Alex Tavarez Date: Sun, 23 Nov 2025 12:36:33 -0500 Subject: [PATCH] Added Argdown plugin capabilities --- quartz/plugins/transformers/ofm.ts | 106 +++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts index b56ba0f..71210ef 100644 --- a/quartz/plugins/transformers/ofm.ts +++ b/quartz/plugins/transformers/ofm.ts @@ -22,6 +22,8 @@ import checkboxScript from "../../components/scripts/checkbox.inline" // @ts-ignore import mermaidScript from "../../components/scripts/mermaid.inline" import mermaidStyle from "../../components/styles/mermaid.inline.scss" +import argdownScript from "../../components/scripts/argdown.inline" +import argdownStyle from "../../components/styles/argdown.inline.scss" import { FilePath, pathToRoot, slugTag, slugifyFilePath } from "../../util/path" import { toHast } from "mdast-util-to-hast" import { toHtml } from "hast-util-to-html" @@ -34,6 +36,7 @@ export interface Options { wikilinks: boolean callouts: boolean mermaid: boolean + argdown: boolean parseTags: boolean parseArrows: boolean parseBlockReferences: boolean @@ -50,6 +53,7 @@ const defaultOptions: Options = { wikilinks: true, callouts: true, mermaid: true, + argdown: true, parseTags: true, parseArrows: true, parseBlockReferences: true, @@ -538,6 +542,24 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin> }) } + if (opts.argdown) { + plugins.push(() => { + return (tree: Root, file) => { + visit(tree, "code", (node: Code) => { + if (node.lang === "argdown") { + file.data.hasArgdownDiagram = true + node.data = { + hProperties: { + className: ["argdown"], + "data-clipboard": JSON.stringify(node.value), + }, + } + } + }) + } + }) + } + return plugins }, htmlPlugins() { @@ -743,6 +765,75 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin> }) } + if (opts.argdown) { + plugins.push(() => { + return (tree: HtmlRoot, _file) => { + visit(tree, "element", (node: Element, _idx, parent) => { + if ( + node.tagName === "code" && + ((node.properties?.className ?? []) as string[])?.includes("argdown") + ) { + parent!.children = [ + { + type: "element", + tagName: "button", + properties: { + className: ["expand-button"], + "aria-label": "Expand argdown diagram", + "data-view-component": true, + }, + children: [ + { + type: "element", + tagName: "svg", + properties: { + width: 16, + height: 16, + viewBox: "0 0 16 16", + fill: "currentColor", + }, + children: [ + { + type: "element", + tagName: "path", + properties: { + fillRule: "evenodd", + d: "M3.72 3.72a.75.75 0 011.06 1.06L2.56 7h10.88l-2.22-2.22a.75.75 0 011.06-1.06l3.5 3.5a.75.75 0 010 1.06l-3.5 3.5a.75.75 0 11-1.06-1.06l2.22-2.22H2.56l2.22 2.22a.75.75 0 11-1.06 1.06l-3.5-3.5a.75.75 0 010-1.06l3.5-3.5z", + }, + children: [], + }, + ], + }, + ], + }, + node, + { + type: "element", + tagName: "div", + properties: { id: "argdown-container", role: "dialog" }, + children: [ + { + type: "element", + tagName: "div", + properties: { id: "argdown-space" }, + children: [ + { + type: "element", + tagName: "div", + properties: { className: ["argdown-content"] }, + children: [], + }, + ], + }, + ], + }, + ] + } + }) + } + }) + } + return plugins }, externalResources() { @@ -779,6 +870,20 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin> }) } + if (opts.argdown) { + js.push({ + script: argdownScript, + loadTime: "afterDOMReady", + contentType: "inline", + moduleType: "module", + }) + + css.push({ + content: argdownStyle, + inline: true, + }) + } + return { js, css } }, } @@ -789,5 +894,6 @@ declare module "vfile" { blocks: Record htmlAst: HtmlRoot hasMermaidDiagram: boolean | undefined + hasArgdownDiagram: boolean | undefined } }