@jay-framework/markdown 0.22.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/agent-kit/designer/markdown-usage.md +186 -0
- package/dist/contracts/markdown-content.jay-contract +13 -0
- package/dist/contracts/markdown-live.jay-contract +14 -0
- package/dist/contracts/markdown-pages.jay-contract +53 -0
- package/dist/index.client.js +95495 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +308 -0
- package/package.json +58 -0
- package/plugin.yaml +18 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as _jay_framework_fullstack_component from '@jay-framework/fullstack-component';
|
|
2
|
+
import { HeadTag } from '@jay-framework/fullstack-component';
|
|
3
|
+
import * as _jay_framework_component from '@jay-framework/component';
|
|
4
|
+
|
|
5
|
+
interface MarkdownPagesProps {
|
|
6
|
+
contentDir: string;
|
|
7
|
+
slug: string;
|
|
8
|
+
}
|
|
9
|
+
declare const markdownPages: _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [], MarkdownPagesProps & {
|
|
10
|
+
slug: string;
|
|
11
|
+
}, {
|
|
12
|
+
slug: string;
|
|
13
|
+
}, _jay_framework_component.JayComponentCore<MarkdownPagesProps & {
|
|
14
|
+
slug: string;
|
|
15
|
+
}, any>> & {
|
|
16
|
+
withFastRender<NewCarryForward extends object>(fastRender: _jay_framework_fullstack_component.RenderFast<[{}], MarkdownPagesProps & {
|
|
17
|
+
slug: string;
|
|
18
|
+
}, any, NewCarryForward>): _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [_jay_framework_fullstack_component.Signals<any>, NewCarryForward], MarkdownPagesProps & {
|
|
19
|
+
slug: string;
|
|
20
|
+
}, {
|
|
21
|
+
slug: string;
|
|
22
|
+
}, _jay_framework_component.JayComponentCore<MarkdownPagesProps & {
|
|
23
|
+
slug: string;
|
|
24
|
+
}, any>> & {
|
|
25
|
+
withClientDefaults(fn: (props: MarkdownPagesProps & {
|
|
26
|
+
slug: string;
|
|
27
|
+
}) => {
|
|
28
|
+
viewState: any;
|
|
29
|
+
carryForward?: any;
|
|
30
|
+
}): _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [_jay_framework_fullstack_component.Signals<any>, NewCarryForward], MarkdownPagesProps & {
|
|
31
|
+
slug: string;
|
|
32
|
+
}, {
|
|
33
|
+
slug: string;
|
|
34
|
+
}, _jay_framework_component.JayComponentCore<MarkdownPagesProps & {
|
|
35
|
+
slug: string;
|
|
36
|
+
}, any>> & any;
|
|
37
|
+
withInteractive(comp: _jay_framework_component.ComponentConstructor<MarkdownPagesProps & {
|
|
38
|
+
slug: string;
|
|
39
|
+
}, any, any, [_jay_framework_fullstack_component.Signals<any>, NewCarryForward], _jay_framework_component.JayComponentCore<MarkdownPagesProps & {
|
|
40
|
+
slug: string;
|
|
41
|
+
}, any>>): _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [_jay_framework_fullstack_component.Signals<any>, NewCarryForward], MarkdownPagesProps & {
|
|
42
|
+
slug: string;
|
|
43
|
+
}, {
|
|
44
|
+
slug: string;
|
|
45
|
+
}, _jay_framework_component.JayComponentCore<MarkdownPagesProps & {
|
|
46
|
+
slug: string;
|
|
47
|
+
}, any>>;
|
|
48
|
+
};
|
|
49
|
+
withInteractive(comp: _jay_framework_component.ComponentConstructor<MarkdownPagesProps & {
|
|
50
|
+
slug: string;
|
|
51
|
+
}, any, any, [], _jay_framework_component.JayComponentCore<MarkdownPagesProps & {
|
|
52
|
+
slug: string;
|
|
53
|
+
}, any>>): _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [], MarkdownPagesProps & {
|
|
54
|
+
slug: string;
|
|
55
|
+
}, {
|
|
56
|
+
slug: string;
|
|
57
|
+
}, _jay_framework_component.JayComponentCore<MarkdownPagesProps & {
|
|
58
|
+
slug: string;
|
|
59
|
+
}, any>>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
interface MarkdownContentProps {
|
|
63
|
+
markdown: string;
|
|
64
|
+
}
|
|
65
|
+
declare const markdownContent: _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [], MarkdownContentProps, {}, _jay_framework_component.JayComponentCore<MarkdownContentProps, any>> & {
|
|
66
|
+
withFastRender<NewCarryForward extends object>(fastRender: _jay_framework_fullstack_component.RenderFast<[{}], MarkdownContentProps, any, NewCarryForward>): _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [_jay_framework_fullstack_component.Signals<any>, NewCarryForward], MarkdownContentProps, {}, _jay_framework_component.JayComponentCore<MarkdownContentProps, any>> & {
|
|
67
|
+
withClientDefaults(fn: (props: MarkdownContentProps) => {
|
|
68
|
+
viewState: any;
|
|
69
|
+
carryForward?: any;
|
|
70
|
+
}): _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [_jay_framework_fullstack_component.Signals<any>, NewCarryForward], MarkdownContentProps, {}, _jay_framework_component.JayComponentCore<MarkdownContentProps, any>> & any;
|
|
71
|
+
withInteractive(comp: _jay_framework_component.ComponentConstructor<MarkdownContentProps, any, any, [_jay_framework_fullstack_component.Signals<any>, NewCarryForward], _jay_framework_component.JayComponentCore<MarkdownContentProps, any>>): _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [_jay_framework_fullstack_component.Signals<any>, NewCarryForward], MarkdownContentProps, {}, _jay_framework_component.JayComponentCore<MarkdownContentProps, any>>;
|
|
72
|
+
};
|
|
73
|
+
withInteractive(comp: _jay_framework_component.ComponentConstructor<MarkdownContentProps, any, any, [], _jay_framework_component.JayComponentCore<MarkdownContentProps, any>>): _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [{}], [], MarkdownContentProps, {}, _jay_framework_component.JayComponentCore<MarkdownContentProps, any>>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
interface MarkdownLiveProps {
|
|
77
|
+
markdown: string;
|
|
78
|
+
}
|
|
79
|
+
declare const markdownLive: _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [], [_jay_framework_fullstack_component.Signals<any>, {}], MarkdownLiveProps, {}, _jay_framework_component.JayComponentCore<MarkdownLiveProps, any>>;
|
|
80
|
+
|
|
81
|
+
interface ParsedMarkdown {
|
|
82
|
+
frontmatter: Record<string, any>;
|
|
83
|
+
html: string;
|
|
84
|
+
}
|
|
85
|
+
declare function extractFrontmatter(content: string): {
|
|
86
|
+
frontmatter: Record<string, any>;
|
|
87
|
+
body: string;
|
|
88
|
+
};
|
|
89
|
+
declare function parseMarkdownBody(markdown: string): string;
|
|
90
|
+
declare function parseMarkdownBodyWithMermaid(markdown: string): Promise<string>;
|
|
91
|
+
declare function parseMarkdown(content: string): ParsedMarkdown;
|
|
92
|
+
declare function parseMarkdownWithMermaid(content: string): Promise<ParsedMarkdown>;
|
|
93
|
+
|
|
94
|
+
declare function highlightCode(code: string, lang: string): string;
|
|
95
|
+
|
|
96
|
+
declare function frontmatterToHeadTags(fm: Record<string, any>): HeadTag[];
|
|
97
|
+
|
|
98
|
+
declare function renderMermaidToSvg(code: string): Promise<string>;
|
|
99
|
+
declare function renderMermaidBlock(code: string): Promise<string>;
|
|
100
|
+
|
|
101
|
+
export { extractFrontmatter, frontmatterToHeadTags, highlightCode, markdownContent, markdownLive, markdownPages, parseMarkdown, parseMarkdownBody, parseMarkdownBodyWithMermaid, parseMarkdownWithMermaid, renderMermaidBlock, renderMermaidToSvg };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { makeJayStackComponent, phaseOutput } from "@jay-framework/fullstack-component";
|
|
2
|
+
import { Marked } from "marked";
|
|
3
|
+
import yaml from "js-yaml";
|
|
4
|
+
import { renderMermaidSVGAsync } from "beautiful-mermaid";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
const ESCAPE_MAP = {
|
|
8
|
+
"&": "&",
|
|
9
|
+
"<": "<",
|
|
10
|
+
">": ">",
|
|
11
|
+
'"': """
|
|
12
|
+
};
|
|
13
|
+
function esc(s) {
|
|
14
|
+
return s.replace(/[&<>"]/g, (c) => ESCAPE_MAP[c]);
|
|
15
|
+
}
|
|
16
|
+
function wrap(cls, text) {
|
|
17
|
+
return `<span class="token ${cls}">${esc(text)}</span>`;
|
|
18
|
+
}
|
|
19
|
+
const JS_KEYWORDS = /\b(async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|from|function|if|import|in|instanceof|let|new|of|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|true|false|null|undefined)\b/;
|
|
20
|
+
const JS_RULES = [
|
|
21
|
+
{ cls: "comment", re: /\/\/[^\n]*|\/\*[\s\S]*?\*\//g },
|
|
22
|
+
{ cls: "string", re: /`(?:[^`\\]|\\.)*`|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g },
|
|
23
|
+
{ cls: "keyword", re: new RegExp(JS_KEYWORDS.source, "g") },
|
|
24
|
+
{ cls: "number", re: /\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/gi },
|
|
25
|
+
{ cls: "function", re: /\b([a-zA-Z_$][\w$]*)\s*(?=\()/g },
|
|
26
|
+
{ cls: "operator", re: /[+\-*/%=!<>&|^~?:]+/g },
|
|
27
|
+
{ cls: "punctuation", re: /[{}[\]();,.]/g }
|
|
28
|
+
];
|
|
29
|
+
const HTML_RULES = [
|
|
30
|
+
{ cls: "comment", re: /<!--[\s\S]*?-->/g },
|
|
31
|
+
{ cls: "tag", re: /<\/?[a-zA-Z][\w-]*/g },
|
|
32
|
+
{ cls: "attribute", re: /\b[a-zA-Z-]+(?==)/g },
|
|
33
|
+
{ cls: "string", re: /"[^"]*"|'[^']*'/g },
|
|
34
|
+
{ cls: "punctuation", re: /[<>=/]/g }
|
|
35
|
+
];
|
|
36
|
+
const CSS_RULES = [
|
|
37
|
+
{ cls: "comment", re: /\/\*[\s\S]*?\*\//g },
|
|
38
|
+
{ cls: "string", re: /"[^"]*"|'[^']*'/g },
|
|
39
|
+
{ cls: "keyword", re: /@[a-zA-Z-]+/g },
|
|
40
|
+
{ cls: "number", re: /\b\d+(?:\.\d+)?(?:px|em|rem|%|vh|vw|s|ms|deg)?\b/g },
|
|
41
|
+
{ cls: "function", re: /\b[a-zA-Z-]+(?=\()/g },
|
|
42
|
+
{ cls: "punctuation", re: /[{}:;,()]/g }
|
|
43
|
+
];
|
|
44
|
+
const YAML_RULES = [
|
|
45
|
+
{ cls: "comment", re: /#[^\n]*/g },
|
|
46
|
+
{ cls: "string", re: /"[^"]*"|'[^']*'/g },
|
|
47
|
+
{ cls: "keyword", re: /^[a-zA-Z_][\w-]*(?=\s*:)/gm },
|
|
48
|
+
{ cls: "number", re: /\b\d+(?:\.\d+)?\b/g },
|
|
49
|
+
{ cls: "punctuation", re: /[-:[\]{}|>]/g }
|
|
50
|
+
];
|
|
51
|
+
const JSON_RULES = [
|
|
52
|
+
{ cls: "string", re: /"(?:[^"\\]|\\.)*"/g },
|
|
53
|
+
{ cls: "number", re: /\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/gi },
|
|
54
|
+
{ cls: "keyword", re: /\b(true|false|null)\b/g },
|
|
55
|
+
{ cls: "punctuation", re: /[{}[\]:,]/g }
|
|
56
|
+
];
|
|
57
|
+
const BASH_RULES = [
|
|
58
|
+
{ cls: "comment", re: /#[^\n]*/g },
|
|
59
|
+
{ cls: "string", re: /"(?:[^"\\]|\\.)*"|'[^']*'/g },
|
|
60
|
+
{
|
|
61
|
+
cls: "keyword",
|
|
62
|
+
re: /\b(if|then|else|elif|fi|for|while|do|done|case|esac|function|return|exit|export|source|local|readonly|declare|set|unset|cd|echo|printf|test)\b/g
|
|
63
|
+
},
|
|
64
|
+
{ cls: "function", re: /\b[a-zA-Z_][\w-]*(?=\s)/g },
|
|
65
|
+
{ cls: "operator", re: /[|&;<>!$]+/g },
|
|
66
|
+
{ cls: "punctuation", re: /[(){}[\]]/g }
|
|
67
|
+
];
|
|
68
|
+
const PYTHON_RULES = [
|
|
69
|
+
{ cls: "comment", re: /#[^\n]*/g },
|
|
70
|
+
{ cls: "string", re: /"""[\s\S]*?"""|'''[\s\S]*?'''|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g },
|
|
71
|
+
{
|
|
72
|
+
cls: "keyword",
|
|
73
|
+
re: /\b(and|as|assert|async|await|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield|True|False|None)\b/g
|
|
74
|
+
},
|
|
75
|
+
{ cls: "number", re: /\b\d+(?:\.\d+)?(?:e[+-]?\d+)?j?\b/gi },
|
|
76
|
+
{ cls: "function", re: /\b([a-zA-Z_]\w*)\s*(?=\()/g },
|
|
77
|
+
{ cls: "operator", re: /[+\-*/%=!<>&|^~@:]+/g },
|
|
78
|
+
{ cls: "punctuation", re: /[{}[\]();,.]/g }
|
|
79
|
+
];
|
|
80
|
+
const LANG_RULES = {
|
|
81
|
+
javascript: JS_RULES,
|
|
82
|
+
js: JS_RULES,
|
|
83
|
+
typescript: JS_RULES,
|
|
84
|
+
ts: JS_RULES,
|
|
85
|
+
jsx: JS_RULES,
|
|
86
|
+
tsx: JS_RULES,
|
|
87
|
+
html: HTML_RULES,
|
|
88
|
+
xml: HTML_RULES,
|
|
89
|
+
css: CSS_RULES,
|
|
90
|
+
scss: CSS_RULES,
|
|
91
|
+
yaml: YAML_RULES,
|
|
92
|
+
yml: YAML_RULES,
|
|
93
|
+
json: JSON_RULES,
|
|
94
|
+
bash: BASH_RULES,
|
|
95
|
+
sh: BASH_RULES,
|
|
96
|
+
shell: BASH_RULES,
|
|
97
|
+
python: PYTHON_RULES,
|
|
98
|
+
py: PYTHON_RULES
|
|
99
|
+
};
|
|
100
|
+
function highlightCode(code, lang) {
|
|
101
|
+
const rules = LANG_RULES[lang.toLowerCase()];
|
|
102
|
+
if (!rules)
|
|
103
|
+
return esc(code);
|
|
104
|
+
const tokens = [];
|
|
105
|
+
for (const rule of rules) {
|
|
106
|
+
const re = new RegExp(rule.re.source, rule.re.flags);
|
|
107
|
+
let match;
|
|
108
|
+
while ((match = re.exec(code)) !== null) {
|
|
109
|
+
tokens.push({
|
|
110
|
+
start: match.index,
|
|
111
|
+
end: match.index + match[0].length,
|
|
112
|
+
cls: rule.cls,
|
|
113
|
+
text: match[0]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
tokens.sort((a, b) => a.start - b.start || b.end - a.end);
|
|
118
|
+
const result = [];
|
|
119
|
+
let pos = 0;
|
|
120
|
+
for (const token of tokens) {
|
|
121
|
+
if (token.start < pos)
|
|
122
|
+
continue;
|
|
123
|
+
if (token.start > pos)
|
|
124
|
+
result.push(esc(code.slice(pos, token.start)));
|
|
125
|
+
result.push(wrap(token.cls, token.text));
|
|
126
|
+
pos = token.end;
|
|
127
|
+
}
|
|
128
|
+
if (pos < code.length)
|
|
129
|
+
result.push(esc(code.slice(pos)));
|
|
130
|
+
return result.join("");
|
|
131
|
+
}
|
|
132
|
+
async function renderMermaidToSvg(code) {
|
|
133
|
+
try {
|
|
134
|
+
return await renderMermaidSVGAsync(code);
|
|
135
|
+
} catch {
|
|
136
|
+
const escaped = code.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
137
|
+
return `<pre class="md-mermaid-error">Failed to render mermaid diagram:
|
|
138
|
+
${escaped}</pre>`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function renderMermaidBlock(code) {
|
|
142
|
+
const svg = await renderMermaidToSvg(code);
|
|
143
|
+
return `<div class="md-mermaid">${svg}</div>
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
146
|
+
function extractFrontmatter(content) {
|
|
147
|
+
const match = content.match(/^---\s*\n([\s\S]*?)\n---\s*\n?([\s\S]*)$/);
|
|
148
|
+
if (!match)
|
|
149
|
+
return { frontmatter: {}, body: content };
|
|
150
|
+
const raw = yaml.load(match[1]);
|
|
151
|
+
return {
|
|
152
|
+
frontmatter: raw && typeof raw === "object" ? raw : {},
|
|
153
|
+
body: match[2]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function mermaidFallback(code) {
|
|
157
|
+
const escaped = code.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
158
|
+
return `<div class="md-mermaid"><pre class="md-mermaid-source">${escaped}</pre></div>`;
|
|
159
|
+
}
|
|
160
|
+
const MERMAID_FENCE_RE = /```mermaid\s*\n([\s\S]*?)```/g;
|
|
161
|
+
async function preprocessMermaid(body, renderSvg) {
|
|
162
|
+
if (!body.includes("```mermaid"))
|
|
163
|
+
return body;
|
|
164
|
+
const fences = [];
|
|
165
|
+
let m;
|
|
166
|
+
const re = new RegExp(MERMAID_FENCE_RE.source, "g");
|
|
167
|
+
while ((m = re.exec(body)) !== null) {
|
|
168
|
+
fences.push({ match: m[0], code: m[1].trim() });
|
|
169
|
+
}
|
|
170
|
+
let result = body;
|
|
171
|
+
for (const fence of fences) {
|
|
172
|
+
const replacement = renderSvg ? await renderMermaidBlock(fence.code) : mermaidFallback(fence.code);
|
|
173
|
+
result = result.replace(fence.match, replacement);
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
function createCodeRenderer() {
|
|
178
|
+
return {
|
|
179
|
+
code({ text, lang }) {
|
|
180
|
+
if (lang === "mermaid")
|
|
181
|
+
return mermaidFallback(text) + "\n";
|
|
182
|
+
const language = lang || "";
|
|
183
|
+
const highlighted = highlightCode(text, language);
|
|
184
|
+
const langClass = language ? ` language-${language}` : "";
|
|
185
|
+
return `<pre class="md-code"><code class="${langClass.trim()}">${highlighted}</code></pre>
|
|
186
|
+
`;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
let sharedMarked;
|
|
191
|
+
function getMarked() {
|
|
192
|
+
if (!sharedMarked) {
|
|
193
|
+
sharedMarked = new Marked();
|
|
194
|
+
sharedMarked.use({ renderer: createCodeRenderer() });
|
|
195
|
+
}
|
|
196
|
+
return sharedMarked;
|
|
197
|
+
}
|
|
198
|
+
function parseMarkdownBody(markdown) {
|
|
199
|
+
return getMarked().parse(markdown);
|
|
200
|
+
}
|
|
201
|
+
async function parseMarkdownBodyWithMermaid(markdown) {
|
|
202
|
+
const processed = await preprocessMermaid(markdown, true);
|
|
203
|
+
return getMarked().parse(processed);
|
|
204
|
+
}
|
|
205
|
+
function parseMarkdown(content) {
|
|
206
|
+
const { frontmatter, body } = extractFrontmatter(content);
|
|
207
|
+
const html = parseMarkdownBody(body);
|
|
208
|
+
return { frontmatter, html };
|
|
209
|
+
}
|
|
210
|
+
async function parseMarkdownWithMermaid(content) {
|
|
211
|
+
const { frontmatter, body } = extractFrontmatter(content);
|
|
212
|
+
const html = await parseMarkdownBodyWithMermaid(body);
|
|
213
|
+
return { frontmatter, html };
|
|
214
|
+
}
|
|
215
|
+
const KNOWN_FIELDS = /* @__PURE__ */ new Set([
|
|
216
|
+
"title",
|
|
217
|
+
"description",
|
|
218
|
+
"canonical",
|
|
219
|
+
"image",
|
|
220
|
+
"author",
|
|
221
|
+
"date",
|
|
222
|
+
"tags"
|
|
223
|
+
]);
|
|
224
|
+
function frontmatterToHeadTags(fm) {
|
|
225
|
+
const tags = [];
|
|
226
|
+
if (fm.title) {
|
|
227
|
+
tags.push({ tag: "title", children: fm.title });
|
|
228
|
+
tags.push({ tag: "meta", attrs: { property: "og:title", content: fm.title } });
|
|
229
|
+
}
|
|
230
|
+
if (fm.description) {
|
|
231
|
+
tags.push({ tag: "meta", attrs: { name: "description", content: fm.description } });
|
|
232
|
+
tags.push({ tag: "meta", attrs: { property: "og:description", content: fm.description } });
|
|
233
|
+
}
|
|
234
|
+
if (fm.canonical) {
|
|
235
|
+
tags.push({ tag: "link", attrs: { rel: "canonical", href: fm.canonical } });
|
|
236
|
+
}
|
|
237
|
+
if (fm.image) {
|
|
238
|
+
tags.push({ tag: "meta", attrs: { property: "og:image", content: fm.image } });
|
|
239
|
+
}
|
|
240
|
+
if (fm.author) {
|
|
241
|
+
tags.push({ tag: "meta", attrs: { name: "author", content: fm.author } });
|
|
242
|
+
}
|
|
243
|
+
if (fm.date) {
|
|
244
|
+
tags.push({
|
|
245
|
+
tag: "meta",
|
|
246
|
+
attrs: { property: "article:published_time", content: new Date(fm.date).toISOString() }
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
for (const [key, value] of Object.entries(fm)) {
|
|
250
|
+
if (KNOWN_FIELDS.has(key))
|
|
251
|
+
continue;
|
|
252
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
253
|
+
tags.push({ tag: "meta", attrs: { name: key, content: String(value) } });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return tags;
|
|
257
|
+
}
|
|
258
|
+
const markdownPages = makeJayStackComponent().withProps().withLoadParams(async function* (_services, props) {
|
|
259
|
+
const dir = props?.contentDir;
|
|
260
|
+
if (!dir)
|
|
261
|
+
return;
|
|
262
|
+
try {
|
|
263
|
+
const files = await fs.readdir(dir);
|
|
264
|
+
const slugs = files.filter((f) => f.endsWith(".md")).map((f) => ({ slug: f.replace(/\.md$/, "") }));
|
|
265
|
+
yield slugs;
|
|
266
|
+
} catch {
|
|
267
|
+
yield [];
|
|
268
|
+
}
|
|
269
|
+
}).withSlowlyRender(async (props) => {
|
|
270
|
+
const filePath = path.join(props.contentDir, `${props.slug}.md`);
|
|
271
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
272
|
+
const { frontmatter, html } = await parseMarkdownWithMermaid(content);
|
|
273
|
+
const tags = Array.isArray(frontmatter.tags) ? frontmatter.tags.map((name) => ({ name: String(name) })) : [];
|
|
274
|
+
return phaseOutput(
|
|
275
|
+
{
|
|
276
|
+
title: frontmatter.title ?? "",
|
|
277
|
+
content: html,
|
|
278
|
+
description: frontmatter.description ?? "",
|
|
279
|
+
date: frontmatter.date ? new Date(frontmatter.date).toISOString() : "",
|
|
280
|
+
tags,
|
|
281
|
+
frontmatter: JSON.stringify(frontmatter)
|
|
282
|
+
},
|
|
283
|
+
{},
|
|
284
|
+
{ headTags: frontmatterToHeadTags(frontmatter) }
|
|
285
|
+
);
|
|
286
|
+
});
|
|
287
|
+
const markdownContent = makeJayStackComponent().withProps().withSlowlyRender(
|
|
288
|
+
async (props) => phaseOutput({ html: await parseMarkdownBodyWithMermaid(props.markdown ?? "") }, {})
|
|
289
|
+
);
|
|
290
|
+
const markdownLive = makeJayStackComponent().withProps().withFastRender(
|
|
291
|
+
async (props) => phaseOutput({ html: parseMarkdownBody(props.markdown ?? "") }, {})
|
|
292
|
+
).withInteractive((props) => ({
|
|
293
|
+
render: () => ({ html: parseMarkdownBody(props.markdown()) })
|
|
294
|
+
}));
|
|
295
|
+
export {
|
|
296
|
+
extractFrontmatter,
|
|
297
|
+
frontmatterToHeadTags,
|
|
298
|
+
highlightCode,
|
|
299
|
+
markdownContent,
|
|
300
|
+
markdownLive,
|
|
301
|
+
markdownPages,
|
|
302
|
+
parseMarkdown,
|
|
303
|
+
parseMarkdownBody,
|
|
304
|
+
parseMarkdownBodyWithMermaid,
|
|
305
|
+
parseMarkdownWithMermaid,
|
|
306
|
+
renderMermaidBlock,
|
|
307
|
+
renderMermaidToSvg
|
|
308
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jay-framework/markdown",
|
|
3
|
+
"version": "0.22.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Markdown rendering plugin for Jay Framework — pages from directories, inline content, code highlighting, mermaid diagrams",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"plugin.yaml",
|
|
11
|
+
"agent-kit"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./dist/index.js",
|
|
15
|
+
"./client": "./dist/index.client.js",
|
|
16
|
+
"./plugin.yaml": "./plugin.yaml",
|
|
17
|
+
"./markdown-pages.jay-contract": "./dist/contracts/markdown-pages.jay-contract",
|
|
18
|
+
"./markdown-content.jay-contract": "./dist/contracts/markdown-content.jay-contract",
|
|
19
|
+
"./markdown-live.jay-contract": "./dist/contracts/markdown-live.jay-contract",
|
|
20
|
+
"./themes/markdown-default.css": "./lib/themes/markdown-default.css",
|
|
21
|
+
"./themes/markdown-docs.css": "./lib/themes/markdown-docs.css",
|
|
22
|
+
"./themes/markdown-blog.css": "./lib/themes/markdown-blog.css"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "npm run build:client && npm run build:server && npm run build:copy-assets && npm run build:types",
|
|
26
|
+
"build:client": "vite build",
|
|
27
|
+
"build:server": "vite build --ssr",
|
|
28
|
+
"build:copy-assets": "mkdir -p dist/contracts && cp lib/contracts/*.jay-contract* dist/contracts/",
|
|
29
|
+
"build:types": "tsup lib/index.ts --dts-only --format esm",
|
|
30
|
+
"build:check-types": "tsc",
|
|
31
|
+
"validate": "jay-stack-cli validate-plugin",
|
|
32
|
+
"clean": "rimraf dist",
|
|
33
|
+
"confirm": "npm run clean && npm run build && npm run build:check-types && npm run test",
|
|
34
|
+
"test": "vitest run"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@jay-framework/component": "^0.22.0",
|
|
38
|
+
"@jay-framework/fullstack-component": "^0.22.0",
|
|
39
|
+
"@jay-framework/reactive": "^0.22.0",
|
|
40
|
+
"@jay-framework/runtime": "^0.22.0",
|
|
41
|
+
"@jay-framework/stack-client-runtime": "^0.22.0",
|
|
42
|
+
"@jay-framework/stack-server-runtime": "^0.22.0",
|
|
43
|
+
"beautiful-mermaid": "^1.1.3",
|
|
44
|
+
"js-yaml": "^4.1.0",
|
|
45
|
+
"marked": "^15.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@jay-framework/dev-environment": "^0.22.0",
|
|
49
|
+
"@jay-framework/jay-stack-cli": "^0.22.0",
|
|
50
|
+
"@types/js-yaml": "^4.0.9",
|
|
51
|
+
"@types/node": "^22.15.21",
|
|
52
|
+
"rimraf": "^5.0.5",
|
|
53
|
+
"tsup": "^8.0.1",
|
|
54
|
+
"typescript": "^5.3.3",
|
|
55
|
+
"vite": "^5.0.11",
|
|
56
|
+
"vitest": "^1.2.1"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/plugin.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: markdown
|
|
2
|
+
description: Markdown rendering — pages from directories, inline content, code highlighting, mermaid diagrams
|
|
3
|
+
|
|
4
|
+
contracts:
|
|
5
|
+
- name: markdown-pages
|
|
6
|
+
contract: markdown-pages.jay-contract
|
|
7
|
+
component: markdownPages
|
|
8
|
+
description: Renders a directory of markdown files as routable pages
|
|
9
|
+
|
|
10
|
+
- name: markdown-content
|
|
11
|
+
contract: markdown-content.jay-contract
|
|
12
|
+
component: markdownContent
|
|
13
|
+
description: Renders a markdown string to HTML at build time (slow phase)
|
|
14
|
+
|
|
15
|
+
- name: markdown-live
|
|
16
|
+
contract: markdown-live.jay-contract
|
|
17
|
+
component: markdownLive
|
|
18
|
+
description: Renders markdown with fast+interactive updates
|