Skip to content

Commit

Permalink
adopt dark
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Mar 20, 2024
1 parent 263fe66 commit 20cf7eb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 36 deletions.
8 changes: 6 additions & 2 deletions src/client/stdlib/mermaid.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import mer from "npm:mermaid";
import {Generators} from "observablehq:stdlib";

let nextId = 0;
const theme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "neutral";
mer.initialize({startOnLoad: false, securityLevel: "loose", theme});

(async () => {
for await (const dark of Generators.dark())
mer.initialize({startOnLoad: false, securityLevel: "loose", theme: dark ? "dark" : "neutral"});
})();

export default async function mermaid() {
const root = document.createElement("div");
Expand Down
2 changes: 1 addition & 1 deletion src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function getLiveSource(content: string, tag: string, attributes: Record<string,
: tag === "dot"
? transpileTag(content, "dot", false)
: tag === "mermaid"
? transpileTag(content, "await mermaid", false)
? transpileTag(content, "await dark, mermaid", false)
: undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion test/output/mermaid.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div id="cell-68f6d8d0" class="observablehq observablehq--block observablehq--loading"></div>
<div id="cell-96e42c05" class="observablehq observablehq--block observablehq--loading"></div>
83 changes: 51 additions & 32 deletions test/output/mermaid.md.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,67 @@
"style": null,
"code": [
{
"id": "68f6d8d0",
"id": "96e42c05",
"node": {
"body": {
"type": "AwaitExpression",
"type": "SequenceExpression",
"start": 0,
"end": 68,
"argument": {
"type": "TaggedTemplateExpression",
"start": 6,
"end": 68,
"tag": {
"type": "Identifier",
"start": 6,
"end": 13,
"name": "mermaid"
"end": 74,
"expressions": [
{
"type": "AwaitExpression",
"start": 0,
"end": 10,
"argument": {
"type": "Identifier",
"start": 6,
"end": 10,
"name": "dark"
}
},
"quasi": {
"type": "TemplateLiteral",
"start": 13,
"end": 68,
"expressions": [],
"quasis": [
{
"type": "TemplateElement",
"start": 14,
"end": 67,
"value": {
"raw": "graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;",
"cooked": "graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;"
},
"tail": true
}
]
{
"type": "TaggedTemplateExpression",
"start": 12,
"end": 74,
"tag": {
"type": "Identifier",
"start": 12,
"end": 19,
"name": "mermaid"
},
"quasi": {
"type": "TemplateLiteral",
"start": 19,
"end": 74,
"expressions": [],
"quasis": [
{
"type": "TemplateElement",
"start": 20,
"end": 73,
"value": {
"raw": "graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;",
"cooked": "graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;"
},
"tail": true
}
]
}
}
}
]
},
"declarations": null,
"references": [
{
"type": "Identifier",
"start": 6,
"end": 13,
"end": 10,
"name": "dark"
},
{
"type": "Identifier",
"start": 12,
"end": 19,
"name": "mermaid"
}
],
Expand All @@ -54,7 +73,7 @@
"expression": true,
"async": true,
"inline": false,
"input": "await mermaid`graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;`"
"input": "await dark, mermaid`graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;`"
}
}
]
Expand Down

0 comments on commit 20cf7eb

Please sign in to comment.