chore: commit dist/ and remove prepare script

Pre-built output is now committed to the repository so that
Quartz can skip the build step during plugin installation.
The prepare script is removed to prevent redundant builds
when installing from npm/git.
This commit is contained in:
saberzero1 2026-03-14 22:01:20 +01:00
parent 4c3ef17cd8
commit 63699e9484
No known key found for this signature in database
5 changed files with 187 additions and 25 deletions

1
.gitignore vendored
View file

@ -4,7 +4,6 @@ node_modules/
.pnp.js
# Build output
dist/
build/
*.tsbuildinfo

166
dist/index.js vendored Normal file
View file

@ -0,0 +1,166 @@
import { visit } from 'unist-util-visit';
import { findAndReplace } from 'mdast-util-find-and-replace';
// src/transformer.ts
var defaultOptions = {
orComponent: true,
TODOComponent: true,
DONEComponent: true,
videoComponent: true,
audioComponent: true,
pdfComponent: true,
blockquoteComponent: true,
tableComponent: true,
attributeComponent: true
};
var orRegex = new RegExp(/{{or:(.*?)}}/, "g");
var TODORegex = new RegExp(/{{.*?\bTODO\b.*?}}/, "g");
var DONERegex = new RegExp(/{{.*?\bDONE\b.*?}}/, "g");
var blockquoteRegex = new RegExp(/(\[\[>\]\])\s*(.*)/, "g");
var roamHighlightRegex = new RegExp(/\^\^(.+)\^\^/, "g");
var roamItalicRegex = new RegExp(/__(.+)__/, "g");
function isSpecialEmbed(node) {
if (node.children.length !== 2) return false;
const [textNode, linkNode] = node.children;
return !!(textNode && textNode.type === "text" && textNode.value.startsWith("{{[[") && linkNode && linkNode.type === "link" && linkNode.children && linkNode.children[0] && linkNode.children[0].type === "text" && linkNode.children[0].value.endsWith("}}"));
}
function transformSpecialEmbed(node, opts) {
const [textNode, linkNode] = node.children;
const embedType = textNode.value.match(/\{\{\[\[(.*?)\]\]:/)?.[1]?.toLowerCase();
const url = linkNode.url.slice(0, -2);
switch (embedType) {
case "audio":
return opts.audioComponent ? {
type: "html",
value: `<audio controls>
<source src="${url}" type="audio/mpeg">
<source src="${url}" type="audio/ogg">
Your browser does not support the audio tag.
</audio>`
} : null;
case "video": {
if (!opts.videoComponent) return null;
const youtubeMatch = url.match(
/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/
);
if (youtubeMatch && youtubeMatch[1]) {
const videoId = youtubeMatch[1].split("&")[0];
const playlistMatch = url.match(/[?&]list=([^#&?]*)/);
const playlistId = playlistMatch ? playlistMatch[1] : null;
return {
type: "html",
value: `<iframe
class="external-embed youtube"
width="600px"
height="350px"
src="https://www.youtube.com/embed/${videoId}${playlistId ? `?list=${playlistId}` : ""}"
frameborder="0"
allow="fullscreen"
></iframe>`
};
} else {
return {
type: "html",
value: `<video controls>
<source src="${url}" type="video/mp4">
<source src="${url}" type="video/webm">
Your browser does not support the video tag.
</video>`
};
}
}
case "pdf":
return opts.pdfComponent ? {
type: "html",
value: `<embed src="${url}" type="application/pdf" width="100%" height="600px" />`
} : null;
default:
return null;
}
}
var RoamFlavoredMarkdown = (userOpts) => {
const opts = { ...defaultOptions, ...userOpts };
return {
name: "RoamFlavoredMarkdown",
markdownPlugins() {
const plugins = [];
plugins.push(() => {
return (tree) => {
const replacements = [];
if (opts.audioComponent || opts.videoComponent || opts.pdfComponent) {
visit(tree, "paragraph", ((node, index, parent) => {
if (isSpecialEmbed(node)) {
const transformedNode = transformSpecialEmbed(node, opts);
if (transformedNode && parent) {
parent.children[index] = transformedNode;
}
}
}));
}
replacements.push([
roamItalicRegex,
(_value, match) => ({
type: "emphasis",
children: [{ type: "text", value: match }]
})
]);
replacements.push([
roamHighlightRegex,
(_value, inner) => ({
type: "html",
value: `<span class="text-highlight">${inner}</span>`
})
]);
if (opts.orComponent) {
replacements.push([
orRegex,
(match) => {
const matchResult = match.match(/{{or:(.*?)}}/);
if (matchResult === null || !matchResult[1]) {
return { type: "html", value: "" };
}
const optionsString = matchResult[1];
const options = optionsString.split("|");
const selectHtml = `<select>${options.map((option) => `<option value="${option}">${option}</option>`).join("")}</select>`;
return { type: "html", value: selectHtml };
}
]);
}
if (opts.TODOComponent) {
replacements.push([
TODORegex,
() => ({
type: "html",
value: `<input type="checkbox" disabled>`
})
]);
}
if (opts.DONEComponent) {
replacements.push([
DONERegex,
() => ({
type: "html",
value: `<input type="checkbox" checked disabled>`
})
]);
}
if (opts.blockquoteComponent) {
replacements.push([
blockquoteRegex,
(_match, _marker, content) => ({
type: "html",
value: `<blockquote>${content.trim()}</blockquote>`
})
]);
}
findAndReplace(tree, replacements);
};
});
return plugins;
}
};
};
export { RoamFlavoredMarkdown };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map

1
dist/index.js.map vendored Normal file

File diff suppressed because one or more lines are too long

43
package-lock.json generated
View file

@ -10,12 +10,7 @@
"license": "MIT",
"dependencies": {
"@quartz-community/types": "github:quartz-community/types",
"mdast": "^3.0.0",
"mdast-util-find-and-replace": "^3.0.1",
"tsup": "^8.5.0",
"typescript": "^5.9.3",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0"
"mdast": "^3.0.0"
},
"devDependencies": {
"@types/hast": "^3.0.4",
@ -27,6 +22,8 @@
"eslint-config-prettier": "^9.1.0",
"preact": "^10.28.2",
"prettier": "^3.6.2",
"tsup": "^8.5.0",
"typescript": "^5.9.3",
"vitest": "^2.1.9"
},
"engines": {
@ -35,14 +32,26 @@
},
"peerDependencies": {
"@jackyzha0/quartz": "^4.5.2",
"preact": "^10.0.0"
"mdast-util-find-and-replace": "^3.0.1",
"preact": "^10.0.0",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0"
},
"peerDependenciesMeta": {
"@jackyzha0/quartz": {
"optional": true
},
"mdast-util-find-and-replace": {
"optional": true
},
"preact": {
"optional": false
},
"unified": {
"optional": true
},
"unist-util-visit": {
"optional": true
}
}
},
@ -2586,6 +2595,7 @@
"resolved": "https://registry.npmjs.org/mdast-util-find-and-replace/-/mdast-util-find-and-replace-3.0.2.tgz",
"integrity": "sha512-Tmd1Vg/m3Xz43afeNxDIhWRtFZgM2VLyaf4vSTYwudTyeuTneoL3qtWMA5jeLyz/O1vDJmmV4QuScFCA2tBPwg==",
"license": "MIT",
"optional": true,
"dependencies": {
"@types/mdast": "^4.0.0",
"escape-string-regexp": "^5.0.0",
@ -2602,6 +2612,7 @@
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz",
"integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==",
"license": "MIT",
"optional": true,
"engines": {
"node": ">=12"
},
@ -2901,7 +2912,6 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"nanoid": "^3.3.11",
"picocolors": "^1.1.1",
@ -3593,6 +3603,7 @@
"resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz",
"integrity": "sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==",
"license": "MIT",
"optional": true,
"dependencies": {
"@types/unist": "^3.0.0"
},
@ -3614,26 +3625,12 @@
"url": "https://opencollective.com/unified"
}
},
"node_modules/unist-util-visit": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.1.0.tgz",
"integrity": "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg==",
"license": "MIT",
"dependencies": {
"@types/unist": "^3.0.0",
"unist-util-is": "^6.0.0",
"unist-util-visit-parents": "^6.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
}
},
"node_modules/unist-util-visit-parents": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.2.tgz",
"integrity": "sha512-goh1s1TBrqSqukSc8wrjwWhL0hiJxgA8m4kFxGlQ+8FYQ3C/m11FcTs4YYem7V664AhHVvgoQLk890Ssdsr2IQ==",
"license": "MIT",
"optional": true,
"dependencies": {
"@types/unist": "^3.0.0",
"unist-util-is": "^6.0.0"

View file

@ -35,7 +35,6 @@
"sideEffects": false,
"scripts": {
"build": "tsup",
"prepare": "npm run build",
"dev": "tsup --watch",
"lint": "eslint . --max-warnings=0",
"format": "prettier . --check",