diff --git a/astro.config.mjs b/astro.config.mjs
index 4fd67c6..ca82598 100644
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -1,10 +1,9 @@
import { defineConfig } from "astro/config";
import solidJs from "@astrojs/solid-js";
-import { remarkAlert } from "remark-github-blockquote-alert";
-import sectionize from "@hbsnow/rehype-sectionize";
import mdx from "@astrojs/mdx";
import pagefind from "./pagefind";
+import { markdownConfig } from "./src/config/io/markdown.ts";
// https://astro.build/config
export default defineConfig({
@@ -15,27 +14,5 @@ export default defineConfig({
mdx(),
pagefind(),
],
- markdown: {
- syntaxHighlight: "shiki",
- shikiConfig: {
- theme: "material-theme-ocean",
- wrap: true,
- },
- remarkPlugins: [
- [
- remarkAlert,
- {
- legacyTitle: true,
- },
- ],
- ],
- rehypePlugins: [
- [
- sectionize,
- {
- idPropertyName: "id",
- },
- ],
- ],
- },
+ markdown: markdownConfig,
});
diff --git a/package.json b/package.json
index 46a0d94..045ccee 100644
--- a/package.json
+++ b/package.json
@@ -12,28 +12,27 @@
"dependencies": {
"@ark-ui/solid": "^3.5.0",
"@astrojs/check": "^0.9.3",
+ "@astrojs/markdown-remark": "^5.1.0",
"@astrojs/mdx": "^3.1.7",
"@astrojs/solid-js": "^4.4.2",
+ "@hbsnow/rehype-sectionize": "^1.0.7",
"@pagefind/default-ui": "^1.1.1",
"@types/node": "^20.14.11",
"astro": "^4.15.9",
"astro-breadcrumbs": "^2.3.1",
+ "hast-util-from-html": "^2.0.3",
"node": "npm:22.7.0",
- "rehype-stringify": "^10.0.1",
"remark-github-blockquote-alert": "^1.2.1",
- "remark-parse": "^11.0.0",
- "remark-rehype": "^11.1.1",
"solid-devtools": "^0.30.1",
"solid-js": "^1.8.18",
"typescript": "^5.5.3",
- "unified": "^11.0.5"
+ "unified": "^11.0.5",
+ "unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@astrojs/ts-plugin": "^1.10.2",
"@biomejs/biome": "^1.8.3",
- "@hbsnow/rehype-sectionize": "^1.0.7",
- "pagefind": "^1.1.1",
- "shiki": "^1.11.0"
+ "pagefind": "^1.1.1"
},
"packageManager": "yarn@4.5.0"
}
diff --git a/src/components/hooks/CreateQMLCodeButtons.astro b/src/components/hooks/CreateQMLCodeButtons.astro
deleted file mode 100644
index 346181a..0000000
--- a/src/components/hooks/CreateQMLCodeButtons.astro
+++ /dev/null
@@ -1,107 +0,0 @@
----
-
----
-
diff --git a/src/components/hooks/TransformLinks.astro b/src/components/hooks/TransformLinks.astro
deleted file mode 100644
index 7d7cca7..0000000
--- a/src/components/hooks/TransformLinks.astro
+++ /dev/null
@@ -1,66 +0,0 @@
----
----
-
diff --git a/src/components/hooks/TransformMDCodeblocks.astro b/src/components/hooks/TransformMDCodeblocks.astro
deleted file mode 100644
index 478cf3d..0000000
--- a/src/components/hooks/TransformMDCodeblocks.astro
+++ /dev/null
@@ -1,21 +0,0 @@
----
----
-
diff --git a/src/components/type/Functions.astro b/src/components/type/Functions.astro
index 11ee9dd..0371e67 100644
--- a/src/components/type/Functions.astro
+++ b/src/components/type/Functions.astro
@@ -3,18 +3,15 @@ import type {
QMLTypeLinkObject,
QuickshellFunction,
} from "@config/io/types";
-import {
- parseMarkdown,
- getQMLTypeLink,
-} from "@config/io/helpers";
+import { getQMLTypeLink } from "@config/io/helpers";
import { Tag } from "@icons";
+import TypeDetails from "./TypeDetails.astro"
export interface Props {
funcData: QuickshellFunction[];
- title: string;
}
-const { funcData, title } = Astro.props;
+const { funcData } = Astro.props;
---
{
@@ -51,9 +48,7 @@ const { funcData, title } = Astro.props;
)
:null
}
-
+
)
})
diff --git a/src/components/type/Properties.astro b/src/components/type/Properties.astro
index 59be51d..a2e705a 100644
--- a/src/components/type/Properties.astro
+++ b/src/components/type/Properties.astro
@@ -1,21 +1,19 @@
---
-import {
- parseMarkdown,
- getQMLTypeLink,
-} from "@config/io/helpers";
+import { getQMLTypeLink } from "@config/io/helpers";
import type {
QMLTypeLinkObject,
QuickshellProps,
} from "@config/io/types";
import { Tag, Flag } from "@icons";
+import TypeDetails from "./TypeDetails.astro"
+
export interface Props {
propsKeys: string[];
propsData: QuickshellProps;
- title: string;
}
-const { propsKeys, propsData, title } = Astro.props;
+const { propsKeys, propsData } = Astro.props;
---
{
@@ -73,9 +71,7 @@ const { propsKeys, propsData, title } = Astro.props;
):null
}
-
+
)
})
diff --git a/src/components/type/Signals.astro b/src/components/type/Signals.astro
index 067541b..28ed2fe 100644
--- a/src/components/type/Signals.astro
+++ b/src/components/type/Signals.astro
@@ -1,15 +1,14 @@
---
import type { QuickshellSignal } from "@config/io/types";
import { Tag, PowerCord } from "@icons";
-import { parseMarkdown } from "@config/io/helpers";
+import TypeDetails from "./TypeDetails.astro";
export interface Props {
signalKeys: string[];
signalsData: QuickshellSignal;
- title: string;
}
-const { signalKeys, signalsData, title } = Astro.props;
+const { signalKeys, signalsData } = Astro.props;
---
{
@@ -44,9 +43,7 @@ const { signalKeys, signalsData, title } = Astro.props;
) : null
}
-
+
)
})
diff --git a/src/components/type/TypeDetails.astro b/src/components/type/TypeDetails.astro
new file mode 100644
index 0000000..ff8ef2f
--- /dev/null
+++ b/src/components/type/TypeDetails.astro
@@ -0,0 +1,14 @@
+---
+import { processQsMarkdown } from "@config/io/helpers"
+
+export interface Props {
+ markdown?: string,
+}
+
+const { markdown } = Astro.props;
+
+const html = markdown ? await processQsMarkdown(markdown) : null;
+---
+
+ {html ? : No details provided}
+
diff --git a/src/components/type/Variants.astro b/src/components/type/Variants.astro
index b074f73..0354951 100644
--- a/src/components/type/Variants.astro
+++ b/src/components/type/Variants.astro
@@ -1,15 +1,14 @@
---
import type { QuickshellVariant } from "@config/io/types";
import { FourDiamonds } from "../icons";
-import { parseMarkdown } from "@src/config/io/helpers";
+import TypeDetails from "./TypeDetails.astro";
export interface Props {
variantKeys: string[];
variantsData: QuickshellVariant;
- title: string;
}
-const { variantKeys, variantsData, title } = Astro.props;
+const { variantKeys, variantsData } = Astro.props;
---
{
@@ -34,9 +33,7 @@ const { variantKeys, variantsData, title } = Astro.props;
)
:null
}
-
+
)
})
diff --git a/src/config/io/helpers.ts b/src/config/io/helpers.ts
index 2fcd4ec..cca7e06 100644
--- a/src/config/io/helpers.ts
+++ b/src/config/io/helpers.ts
@@ -1,8 +1,4 @@
-import { unified } from "unified";
-import remarkParse from "remark-parse";
-import remarkRehype from "remark-rehype";
-import rehypeStringify from "rehype-stringify";
-import { remarkAlert } from "remark-github-blockquote-alert";
+import * as markdownUtils from "./markdown.ts";
import {
// Flag,
@@ -10,7 +6,8 @@ import {
Tag,
FourDiamonds,
RoundBrackets,
-} from "@icons";
+ // @icons breaks when imported indirectly from astro.config.mjs
+} from "../../components/icons.tsx";
import type {
ConfigHeading,
ConfigTOC,
@@ -78,21 +75,8 @@ export function groupRoutes(routes: RouteData[]): GroupedRoutes {
}, defaultValue);
}
-export function parseMarkdown(text?: string, title?: string) {
- if (!text) {
- return unified()
- .use(remarkParse)
- .use(remarkRehype)
- .use(rehypeStringify)
- .process(title);
- }
-
- return unified()
- .use(remarkParse)
- .use(remarkAlert)
- .use(remarkRehype)
- .use(rehypeStringify)
- .process(text);
+export async function processQsMarkdown(markdown: string): Promise {
+ return await markdownUtils.processMarkdown(markdown);
}
export function getQMLTypeLinkObject(unparsed: string) {
diff --git a/src/config/io/markdown.ts b/src/config/io/markdown.ts
new file mode 100644
index 0000000..e1b2ac4
--- /dev/null
+++ b/src/config/io/markdown.ts
@@ -0,0 +1,108 @@
+import type { Transformer } from "unified";
+import type { Node, Parent } from "unist";
+import { visit, CONTINUE, SKIP } from "unist-util-visit";
+import { fromHtml } from "hast-util-from-html";
+
+import type { AstroMarkdownOptions, MarkdownProcessor } from "@astrojs/markdown-remark";
+import { createMarkdownProcessor } from "@astrojs/markdown-remark";
+
+import { remarkAlert } from "remark-github-blockquote-alert";
+import sectionize from "@hbsnow/rehype-sectionize";
+
+import { getQMLTypeLinkObject, getQMLTypeLink, getIconForLink } from "./helpers.ts"
+
+// couldn't find the actual type to use
+type HtmlNode = Node & {
+ value: string,
+ type: string,
+ tagName: string,
+};
+
+function rehypeRewriteTypelinks(): Transformer {
+ return function (root: Node): Node {
+ // @ts-ignore: does not appear to be a way to give this a correct type, it works for the one with a test below
+ visit(root, (node: HtmlNode, index: number, parent: Parent) => {
+ if (node.type == "element" && node.tagName == "pre") return SKIP;
+
+ if (node.type == "text") {
+ let changed = false;
+
+ node.value = node.value.replace(/TYPE99(\w+.)99TYPE/g, (_full: string, match: string) => {
+ changed = true;
+
+ const linkObject = getQMLTypeLinkObject(match);
+ const link = getQMLTypeLink(linkObject);
+ const icon = (linkObject.mtype && linkObject.mtype != "func") ? getIconForLink(linkObject.mtype, false) : null;
+ const hasParens = linkObject.mtype == "func" || linkObject.mtype == "signal";
+ const hasDot = linkObject.name && linkObject.mname;
+
+ return `${icon ?? ""}${linkObject.name ?? ""}${hasDot ? "." : ""}${linkObject.mname ?? ""}${hasParens ? "()" : ""}`;
+ });
+
+ if (changed) {
+ const fragment = fromHtml(node.value, { fragment: true });
+ parent.children.splice(index, 1, ...fragment.children);
+ return SKIP;
+ }
+ }
+
+ return CONTINUE;
+ });
+
+ return root;
+ }
+}
+
+const shikiRewriteTypelinks = {
+ code: (root: Node) => {
+ visit(root, "text", (node: HtmlNode, index: number, parent: Parent) => {
+ let changed = false;
+
+ node.value = node.value.replace(/TYPE99(\w+.)99TYPE/g, (_full: string, match: string) => {
+ changed = true;
+
+ const linkObject = getQMLTypeLinkObject(match);
+ const link = getQMLTypeLink(linkObject);
+
+ return `${linkObject.name ?? ""}`;
+ });
+
+ if (changed) {
+ const fragment = fromHtml(node.value, { fragment: true });
+ parent.children.splice(index, 1, ...fragment.children);
+ }
+ });
+ }
+};
+
+export const markdownConfig: AstroMarkdownOptions = {
+ syntaxHighlight: "shiki",
+ shikiConfig: {
+ theme: "material-theme-ocean",
+ wrap: true,
+ transformers: [ shikiRewriteTypelinks ],
+ },
+ remarkPlugins: [[
+ remarkAlert,
+ { legacyTitle: true },
+ ]],
+ rehypePlugins: [
+ [ sectionize, { idPropertyName: "id" } ],
+ // @ts-ignore: can't tell what this wants
+ [ rehypeRewriteTypelinks, {} ],
+ ],
+};
+
+let globalMarkdownProcessor: Promise;
+
+async function getMarkdownProcessor(): Promise {
+ if (!globalMarkdownProcessor) {
+ globalMarkdownProcessor = createMarkdownProcessor(markdownConfig);
+ }
+
+ return globalMarkdownProcessor;
+}
+
+export async function processMarkdown(markdown: string): Promise {
+ return (await (await getMarkdownProcessor()).render(markdown)).code;
+}
diff --git a/src/layouts/DocsLayout.astro b/src/layouts/DocsLayout.astro
index c46c247..541a0bc 100644
--- a/src/layouts/DocsLayout.astro
+++ b/src/layouts/DocsLayout.astro
@@ -7,7 +7,6 @@ import PreTheme from "@config/PreTheme.astro";
import Header from "@components/Header.astro";
import Head from "@config/Head.astro";
import Nav from "@components/navigation/sidebars/Nav.astro";
-import CreateQMLCodeButtons from "@components/hooks/CreateQMLCodeButtons.astro";
import "@styles/global.css";
import type { ConfigHeading } from "@src/components/navigation/sidebars/types";
import Footer from "@src/components/Footer.astro";
@@ -63,7 +62,6 @@ if (url[2]) {
-
diff --git a/src/pages/docs/types/[type]/[name].astro b/src/pages/docs/types/[type]/[name].astro
index 70a136e..174a7b6 100644
--- a/src/pages/docs/types/[type]/[name].astro
+++ b/src/pages/docs/types/[type]/[name].astro
@@ -1,6 +1,6 @@
---
import {
- parseMarkdown,
+ processQsMarkdown,
getQMLTypeLink,
} from "@config/io/helpers";
import { generateTypeData } from "@config/io/generateTypeData";
@@ -11,8 +11,6 @@ import Properties from "@components/type/Properties.astro";
import Functions from "@components/type/Functions.astro";
import Signals from "@components/type/Signals.astro";
import Variants from "@components/type/Variants.astro";
-import TransformMDCodeblocks from "@components/hooks/TransformMDCodeblocks.astro";
-import TransformLinks from "@components/hooks/TransformLinks.astro";
export async function getStaticPaths() {
const routes = await generateTypeData();
@@ -51,11 +49,8 @@ const sidebarData = {
const superLink = data.super ? getQMLTypeLink(data.super) : null;
-const details = parseMarkdown(data.details, route.name);
+const details = data.details ? await processQsMarkdown(data.details) : null;
---
-
-
-
@@ -87,34 +82,30 @@ const details = parseMarkdown(data.details, route.name);
))}
):null}
-
+ {details ? : null}
{!details ? ({data.description}):null}
{ data.properties && propsKeys ? (
): null}
{ data.functions && data.functions.length > 0 ? (
): null}
{ data.signals && signalKeys ? (
):null}
{ data.variants && variantKeys ? (
):null}
diff --git a/yarn.lock b/yarn.lock
index 168390b..c700bf3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -138,7 +138,7 @@ __metadata:
languageName: node
linkType: hard
-"@astrojs/markdown-remark@npm:5.2.0":
+"@astrojs/markdown-remark@npm:5.2.0, @astrojs/markdown-remark@npm:^5.1.0":
version: 5.2.0
resolution: "@astrojs/markdown-remark@npm:5.2.0"
dependencies:
@@ -4081,7 +4081,7 @@ __metadata:
languageName: node
linkType: hard
-"hast-util-from-html@npm:^2.0.0, hast-util-from-html@npm:^2.0.1":
+"hast-util-from-html@npm:^2.0.0, hast-util-from-html@npm:^2.0.1, hast-util-from-html@npm:^2.0.3":
version: 2.0.3
resolution: "hast-util-from-html@npm:2.0.3"
dependencies:
@@ -6302,6 +6302,7 @@ __metadata:
dependencies:
"@ark-ui/solid": "npm:^3.5.0"
"@astrojs/check": "npm:^0.9.3"
+ "@astrojs/markdown-remark": "npm:^5.1.0"
"@astrojs/mdx": "npm:^3.1.7"
"@astrojs/solid-js": "npm:^4.4.2"
"@astrojs/ts-plugin": "npm:^1.10.2"
@@ -6311,17 +6312,15 @@ __metadata:
"@types/node": "npm:^20.14.11"
astro: "npm:^4.15.9"
astro-breadcrumbs: "npm:^2.3.1"
+ hast-util-from-html: "npm:^2.0.3"
node: "npm:22.7.0"
pagefind: "npm:^1.1.1"
- rehype-stringify: "npm:^10.0.1"
remark-github-blockquote-alert: "npm:^1.2.1"
- remark-parse: "npm:^11.0.0"
- remark-rehype: "npm:^11.1.1"
- shiki: "npm:^1.11.0"
solid-devtools: "npm:^0.30.1"
solid-js: "npm:^1.8.18"
typescript: "npm:^5.5.3"
unified: "npm:^11.0.5"
+ unist-util-visit: "npm:^5.0.0"
languageName: unknown
linkType: soft
@@ -6382,7 +6381,7 @@ __metadata:
languageName: node
linkType: hard
-"rehype-stringify@npm:^10.0.0, rehype-stringify@npm:^10.0.1":
+"rehype-stringify@npm:^10.0.0":
version: 10.0.1
resolution: "rehype-stringify@npm:10.0.1"
dependencies:
@@ -6473,7 +6472,7 @@ __metadata:
languageName: node
linkType: hard
-"remark-rehype@npm:^11.0.0, remark-rehype@npm:^11.1.0, remark-rehype@npm:^11.1.1":
+"remark-rehype@npm:^11.0.0, remark-rehype@npm:^11.1.0":
version: 11.1.1
resolution: "remark-rehype@npm:11.1.1"
dependencies:
@@ -6830,7 +6829,7 @@ __metadata:
languageName: node
linkType: hard
-"shiki@npm:^1.10.3, shiki@npm:^1.11.0, shiki@npm:^1.16.2":
+"shiki@npm:^1.10.3, shiki@npm:^1.16.2":
version: 1.20.0
resolution: "shiki@npm:1.20.0"
dependencies: