chalk-talk 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/assets/player.html +9 -1
- package/embed-mermaid.js +3810 -167
- package/embed.js +9 -1
- package/markdown.d.ts +7 -0
- package/markdown.js +42 -0
- package/mount.d.ts +5 -0
- package/mount.global.js +3958 -0
- package/mount.js +3 -0
- package/package.json +24 -6
- package/player.js +9 -1
- package/scripts/contract.mjs +1 -1
- package/scripts/mermaid.mjs +3818 -175
package/markdown.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// chalk-talk/markdown: ```chalk-talk and ```chalk-mermaid fences as <div data-chalk-talk> blocks for chalk-talk/mount.
|
|
2
|
+
export function fenceKind(info: string | null | undefined): 'text' | 'mermaid' | undefined
|
|
3
|
+
export function blockHtml(kind: 'text' | 'mermaid', source: string): string
|
|
4
|
+
/** markdown-it plugin: md.use(markdownItChalkTalk). */
|
|
5
|
+
export function markdownItChalkTalk<T>(md: T): T
|
|
6
|
+
/** remark plugin (unified, MDX, Docusaurus): remarkPlugins: [remarkChalkTalk]. */
|
|
7
|
+
export function remarkChalkTalk(): (tree: unknown) => void
|
package/markdown.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// chalk-talk/markdown (engine v0.250.0) — MIT. GENERATED by tools/assets.mjs.
|
|
2
|
+
// player/markdown.ts
|
|
3
|
+
var FENCES = { "chalk-talk": "text", "chalk-mermaid": "mermaid" };
|
|
4
|
+
function fenceKind(info) {
|
|
5
|
+
return FENCES[(info ?? "").trim().split(/\s+/)[0]];
|
|
6
|
+
}
|
|
7
|
+
var escape = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
8
|
+
function blockHtml(kind, source) {
|
|
9
|
+
return `<div class="chalk-talk-block" data-chalk-talk="${kind}"><div class="chalk-talk-source" style="white-space:pre-wrap;font-family:monospace">${escape(source)}</div></div>
|
|
10
|
+
`;
|
|
11
|
+
}
|
|
12
|
+
function markdownItChalkTalk(md) {
|
|
13
|
+
const fence = md.renderer.rules.fence;
|
|
14
|
+
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
|
|
15
|
+
const kind = fenceKind(tokens[idx].info);
|
|
16
|
+
if (kind) return blockHtml(kind, tokens[idx].content);
|
|
17
|
+
return fence ? fence(tokens, idx, options, env, self) : self.renderToken(tokens, idx, options);
|
|
18
|
+
};
|
|
19
|
+
return md;
|
|
20
|
+
}
|
|
21
|
+
function remarkChalkTalk() {
|
|
22
|
+
const walk = (node) => {
|
|
23
|
+
if (node.type === "code") {
|
|
24
|
+
const kind = fenceKind(node.lang);
|
|
25
|
+
if (kind) {
|
|
26
|
+
node.data = {
|
|
27
|
+
hName: "div",
|
|
28
|
+
hProperties: { className: ["chalk-talk-block"], dataChalkTalk: kind },
|
|
29
|
+
hChildren: [{ type: "element", tagName: "div", properties: { className: ["chalk-talk-source"], style: "white-space:pre-wrap;font-family:monospace" }, children: [{ type: "text", value: node.value ?? "" }] }]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const child of node.children ?? []) walk(child);
|
|
34
|
+
};
|
|
35
|
+
return (tree) => walk(tree);
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
blockHtml,
|
|
39
|
+
fenceKind,
|
|
40
|
+
markdownItChalkTalk,
|
|
41
|
+
remarkChalkTalk
|
|
42
|
+
};
|
package/mount.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// chalk-talk/mount: [data-chalk-talk] blocks become lessons (chalk-talk/markdown writes them).
|
|
2
|
+
/** Mounts the blocks inside `root` not mounted yet, and lets go of the ones no longer on the page. */
|
|
3
|
+
export function mountAll(root?: ParentNode): void
|
|
4
|
+
/** Mounts what is on the page now and keeps watching for blocks that appear (once per page). */
|
|
5
|
+
export function watch(): void
|