@mdsvex/render 1.0.0-next.0 → 1.0.0-next.2

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.
@@ -1,139 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { PFMParser, WireEmitter } from '@mdsvex/parse';
3
- import { TreeBuilder } from '@mdsvex/parse/tree-builder';
4
- import { WireTreeBuilder } from '@mdsvex/parse/wire-tree-builder';
5
- import { CursorHTMLRenderer } from '../src/html_cursor';
6
-
7
- // Helpers
8
-
9
- /** Server path: PFMParser -> TreeBuilder -> CursorHTMLRenderer */
10
- function via_tree(source: string): string {
11
- const tree = new TreeBuilder(source.length >> 3 || 128);
12
- const parser = new PFMParser(tree);
13
- parser.parse(source);
14
- const renderer = new CursorHTMLRenderer({ cache: false });
15
- renderer.update(tree.get_buffer(), source);
16
- return renderer.html;
17
- }
18
-
19
- /** Client path: PFMParser -> WireEmitter -> WireTreeBuilder -> CursorHTMLRenderer */
20
- function via_wire(source: string): string {
21
- const emitter = new WireEmitter();
22
- emitter.set_source(source);
23
- const parser = new PFMParser(emitter);
24
- parser.parse(source);
25
- const batch = emitter.flush();
26
-
27
- const builder = new WireTreeBuilder();
28
- builder.apply(batch);
29
- const renderer = new CursorHTMLRenderer({ cache: false });
30
- renderer.update(builder.get_buffer(), '');
31
- return renderer.html;
32
- }
33
-
34
- /** Incremental wire path: byte-by-byte feeding like the viewer */
35
- function via_wire_incremental(source: string): string {
36
- const emitter = new WireEmitter();
37
- const parser = new PFMParser(emitter);
38
- parser.init();
39
-
40
- const batches: unknown[][][] = [];
41
- let accumulated = '';
42
- for (let i = 0; i < source.length; i++) {
43
- const ch = source[i];
44
- accumulated += ch;
45
- emitter.set_source(accumulated);
46
- parser.feed(ch);
47
- batches.push(emitter.flush());
48
- }
49
- emitter.set_source(accumulated);
50
- parser.finish();
51
- batches.push(emitter.flush());
52
-
53
- const builder = new WireTreeBuilder();
54
- for (const batch of batches) {
55
- if (batch.length > 0) builder.apply(batch);
56
- }
57
- const renderer = new CursorHTMLRenderer({ cache: false });
58
- renderer.update(builder.get_buffer(), '');
59
- return renderer.html;
60
- }
61
-
62
- function assert_same(source: string): void {
63
- const from_tree = via_tree(source);
64
- const from_wire = via_wire(source);
65
- expect(from_wire).toBe(from_tree);
66
- }
67
-
68
- function assert_same_incremental(source: string): void {
69
- const from_tree = via_tree(source);
70
- const from_wire = via_wire_incremental(source);
71
- expect(from_wire).toBe(from_tree);
72
- }
73
-
74
- // Tests
75
-
76
- describe('WireTreeBuilder produces same HTML as TreeBuilder', () => {
77
- it('simple paragraph', () => assert_same('hello world\n'));
78
- it('multiple paragraphs', () => assert_same('first\n\nsecond\n'));
79
-
80
- it('heading', () => assert_same('# Hello\n'));
81
- it('h2', () => assert_same('## Title\n'));
82
-
83
- it('emphasis', () => assert_same('_hello_\n'));
84
- it('strong', () => assert_same('*bold*\n'));
85
- it('nested emphasis', () => assert_same('_em *strong* em_\n'));
86
-
87
- it('code span', () => assert_same('use `code` here\n'));
88
- it('code fence with info', () => assert_same('```js\nconst x = 1;\n```\n'));
89
- it('code fence no info', () => assert_same('```\nhello\n```\n'));
90
-
91
- it('block quote', () => assert_same('> quoted\n'));
92
-
93
- it('link', () => assert_same('[click](https://example.com)\n'));
94
- it('link with title', () => assert_same('[text](url "title")\n'));
95
- it('image', () => assert_same('![alt text](image.png)\n'));
96
-
97
- it('unordered list', () => assert_same('- one\n- two\n'));
98
- it('ordered list', () => assert_same('1. one\n2. two\n'));
99
-
100
- it('thematic break', () => assert_same('---\n'));
101
- it('strikethrough', () => assert_same('~~deleted~~\n'));
102
- it('superscript', () => assert_same('^super^\n'));
103
-
104
- it('table', () =>
105
- assert_same('| foo | bar |\n| --- | --- |\n| baz | bim |\n'));
106
- it('table alignment', () =>
107
- assert_same(
108
- '| left | center | right |\n| :--- | :---: | ---: |\n| a | b | c |\n'
109
- ));
110
-
111
- it('html self-closing', () => assert_same('text <br /> more\n'));
112
- it('html paired', () => assert_same('text <span>inside</span> end\n'));
113
- it('html block', () =>
114
- assert_same('<section>\n\n# Heading\n\nParagraph.\n\n</section>\n'));
115
- it('html comment', () => assert_same('text <!-- hidden --> more\n'));
116
-
117
- it('code span with leading space preserved', () => assert_same('` a`\n'));
118
- it('code span with both spaces stripped', () =>
119
- assert_same('`` foo ` bar ``\n'));
120
-
121
- it('revoked emphasis', () => assert_same('_not closed\n'));
122
-
123
- it('code span leading space preserved (incremental)', () =>
124
- assert_same_incremental('` a`\n'));
125
- it('code span both spaces stripped (incremental)', () =>
126
- assert_same_incremental('`` foo ` bar ``\n'));
127
-
128
- it('complex document', () =>
129
- assert_same(
130
- '# Title\n\n' +
131
- 'A paragraph with _emphasis_ and *bold*.\n\n' +
132
- '> A block quote with `code`\n\n' +
133
- '```js\nconst x = 1;\n```\n\n' +
134
- '- item one\n- item two\n\n' +
135
- '| a | b |\n| --- | --- |\n| 1 | 2 |\n\n' +
136
- '[link](url) and ![img](src)\n\n' +
137
- '---\n'
138
- ));
139
- });
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "include": ["src/**/*"],
3
- "compilerOptions": {
4
- "target": "es2020",
5
- "module": "esnext",
6
- "moduleResolution": "bundler",
7
- "forceConsistentCasingInFileNames": true,
8
- "esModuleInterop": true,
9
- "strict": true
10
- }
11
- }
@@ -1,33 +0,0 @@
1
- import { defineConfig } from "vite";
2
- import { resolve } from "path";
3
- // import terser from "@rollup/plugin-terser";
4
-
5
- export default defineConfig({
6
- build: {
7
- lib: {
8
- entry: {
9
- index: resolve(__dirname, "src/index.ts"),
10
- html_cursor: resolve(__dirname, "src/html_cursor.ts"),
11
- component: resolve(__dirname, "src/component.ts"),
12
- mappings: resolve(__dirname, "src/mappings.ts"),
13
- sourcemap: resolve(__dirname, "src/sourcemap.ts"),
14
- },
15
- formats: ["es"],
16
- },
17
- outDir: "dist",
18
- reportCompressedSize: true,
19
- rollupOptions: {
20
- external: [/^@mdsvex\/parse/],
21
- output: {
22
- entryFileNames: "[name].js",
23
- plugins: [
24
- // terser({
25
- // mangle: true,
26
- // compress: true,
27
- // format: { comments: false },
28
- // }),
29
- ],
30
- },
31
- },
32
- },
33
- });