@wireweave/markdown-plugin 1.0.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.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * markdown-it plugin for wireweave
3
+ */
4
+
5
+ import type MarkdownIt from 'markdown-it';
6
+ import { renderWireframe, WireframePluginOptions } from './index';
7
+
8
+ /**
9
+ * markdown-it plugin
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import MarkdownIt from 'markdown-it';
14
+ * import { markdownItWireframe } from '@wireweave/markdown-plugin/markdown-it';
15
+ *
16
+ * const md = new MarkdownIt();
17
+ * md.use(markdownItWireframe, { format: 'svg' });
18
+ *
19
+ * const html = md.render('```wireframe\npage { text "Hello" }\n```');
20
+ * ```
21
+ */
22
+ export function markdownItWireframe(
23
+ md: MarkdownIt,
24
+ options: WireframePluginOptions = {}
25
+ ): void {
26
+ const defaultFence = md.renderer.rules.fence;
27
+
28
+ md.renderer.rules.fence = (tokens, idx, opts, env, self) => {
29
+ const token = tokens[idx];
30
+ const info = token.info.trim();
31
+
32
+ if (info === 'wireframe' || info === 'wf') {
33
+ return renderWireframe(token.content, options);
34
+ }
35
+
36
+ // Use default renderer for other code blocks
37
+ if (defaultFence) {
38
+ return defaultFence(tokens, idx, opts, env, self);
39
+ }
40
+
41
+ return `<pre><code class="language-${info}">${md.utils.escapeHtml(token.content)}</code></pre>`;
42
+ };
43
+ }
package/src/marked.ts ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * marked extension for wireweave
3
+ */
4
+
5
+ import type { MarkedExtension, Tokens } from 'marked';
6
+ import { renderWireframe, WireframePluginOptions } from './index';
7
+
8
+ /**
9
+ * marked extension
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { marked } from 'marked';
14
+ * import { markedWireframe } from '@wireweave/markdown-plugin/marked';
15
+ *
16
+ * marked.use(markedWireframe({ format: 'svg' }));
17
+ *
18
+ * const html = marked.parse('```wireframe\npage { text "Hello" }\n```');
19
+ * ```
20
+ */
21
+ export function markedWireframe(
22
+ options: WireframePluginOptions = {}
23
+ ): MarkedExtension {
24
+ return {
25
+ renderer: {
26
+ code(token: Tokens.Code): string | false {
27
+ if (token.lang === 'wireframe' || token.lang === 'wf') {
28
+ return renderWireframe(token.text, options);
29
+ }
30
+ return false; // Use default renderer
31
+ },
32
+ },
33
+ };
34
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * remarkable plugin for wireweave
3
+ */
4
+
5
+ import { renderWireframe, WireframePluginOptions } from './index';
6
+
7
+ // Type declarations for remarkable (no @types/remarkable available)
8
+ interface RemarkableToken {
9
+ type: string;
10
+ params: string;
11
+ content: string;
12
+ }
13
+
14
+ interface RemarkableRenderer {
15
+ rules: {
16
+ fence: (
17
+ tokens: RemarkableToken[],
18
+ idx: number,
19
+ options: Record<string, unknown>,
20
+ env: Record<string, unknown>
21
+ ) => string;
22
+ };
23
+ }
24
+
25
+ interface RemarkableUtils {
26
+ escapeHtml: (text: string) => string;
27
+ }
28
+
29
+ interface Remarkable {
30
+ renderer: RemarkableRenderer;
31
+ utils: RemarkableUtils;
32
+ }
33
+
34
+ /**
35
+ * remarkable plugin
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { Remarkable } from 'remarkable';
40
+ * import { remarkableWireframe } from '@wireweave/markdown-plugin/remarkable';
41
+ *
42
+ * const md = new Remarkable();
43
+ * md.use(remarkableWireframe({ format: 'svg' }));
44
+ *
45
+ * const html = md.render('```wireframe\npage { text "Hello" }\n```');
46
+ * ```
47
+ */
48
+ /**
49
+ * Escape HTML entities
50
+ */
51
+ function escapeHtml(text: string): string {
52
+ return text
53
+ .replace(/&/g, '&amp;')
54
+ .replace(/</g, '&lt;')
55
+ .replace(/>/g, '&gt;')
56
+ .replace(/"/g, '&quot;');
57
+ }
58
+
59
+ export function remarkableWireframe(
60
+ options: WireframePluginOptions = {}
61
+ ): (md: Remarkable) => void {
62
+ return (md: Remarkable) => {
63
+ const rules = md.renderer.rules;
64
+
65
+ // Override fence rule completely
66
+ rules.fence = (
67
+ tokens: RemarkableToken[],
68
+ idx: number,
69
+ _opts: Record<string, unknown>,
70
+ _env: Record<string, unknown>
71
+ ): string => {
72
+ const token = tokens[idx];
73
+ const lang = token.params || '';
74
+
75
+ if (lang === 'wireframe' || lang === 'wf') {
76
+ return renderWireframe(token.content, options);
77
+ }
78
+
79
+ // Render other code blocks with syntax highlighting class
80
+ const langClass = lang ? ` class="language-${escapeHtml(lang)}"` : '';
81
+ return `<pre><code${langClass}>${escapeHtml(token.content)}</code></pre>\n`;
82
+ };
83
+ };
84
+ }