@wsxjs/wsx-marked-components 0.0.19 → 0.0.21
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/dist/index.cjs +1 -1
- package/dist/index.js +1023 -1250
- package/package.json +5 -5
- package/src/List.wsx +1 -24
- package/src/Markdown.wsx +2 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wsxjs/wsx-marked-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "Markdown rendering components built with WSXJS for marked library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"marked": "^12.0.0",
|
|
22
|
-
"@wsxjs/wsx-core": "0.0.
|
|
23
|
-
"@wsxjs/wsx-logger": "0.0.
|
|
22
|
+
"@wsxjs/wsx-core": "0.0.21",
|
|
23
|
+
"@wsxjs/wsx-logger": "0.0.21"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"tsup": "^8.0.0",
|
|
30
30
|
"typescript": "^5.0.0",
|
|
31
31
|
"vite": "^5.4.19",
|
|
32
|
-
"@wsxjs/
|
|
33
|
-
"@wsxjs/
|
|
32
|
+
"@wsxjs/wsx-vite-plugin": "0.0.21",
|
|
33
|
+
"@wsxjs/eslint-plugin-wsx": "0.0.21"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"wsx",
|
package/src/List.wsx
CHANGED
|
@@ -9,32 +9,9 @@ import { LightComponent, autoRegister, state } from "@wsxjs/wsx-core";
|
|
|
9
9
|
@autoRegister({ tagName: "wsx-marked-list" })
|
|
10
10
|
export default class List extends LightComponent {
|
|
11
11
|
@state private ordered: boolean = false;
|
|
12
|
+
// internal list items
|
|
12
13
|
@state private items: string[] = [];
|
|
13
14
|
|
|
14
|
-
constructor() {
|
|
15
|
-
super({
|
|
16
|
-
styleName: "wsx-marked-list",
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static get observedAttributes() {
|
|
21
|
-
return ["ordered", "items"];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
25
|
-
if (name === "ordered") {
|
|
26
|
-
this.ordered = newValue === "true";
|
|
27
|
-
} else if (name === "items") {
|
|
28
|
-
try {
|
|
29
|
-
// HTML 属性值会被浏览器自动解码,所以这里得到的是原始的 JSON 字符串
|
|
30
|
-
// JSON.parse 会解析出包含 HTML 字符串的数组
|
|
31
|
-
this.items = JSON.parse(newValue || "[]");
|
|
32
|
-
} catch {
|
|
33
|
-
this.items = [];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
15
|
render() {
|
|
39
16
|
if (this.ordered) {
|
|
40
17
|
return (
|
package/src/Markdown.wsx
CHANGED
|
@@ -15,7 +15,7 @@ import { LightComponent, autoRegister, state } from "@wsxjs/wsx-core";
|
|
|
15
15
|
import { createLogger } from "@wsxjs/wsx-logger";
|
|
16
16
|
import { marked } from "marked";
|
|
17
17
|
import type { Tokens } from "marked";
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
import { renderInlineTokens } from "./marked-utils";
|
|
20
20
|
// Import WSX components so they're registered as custom elements
|
|
21
21
|
import "./Heading.wsx";
|
|
@@ -54,26 +54,6 @@ export default class Markdown extends LightComponent {
|
|
|
54
54
|
@state private markdown: string = "";
|
|
55
55
|
private customRenderers: CustomRenderers = {};
|
|
56
56
|
|
|
57
|
-
constructor() {
|
|
58
|
-
super({
|
|
59
|
-
styles,
|
|
60
|
-
styleName: "wsx-markdown",
|
|
61
|
-
lightDOM: true,
|
|
62
|
-
});
|
|
63
|
-
logger.info("Markdown initialized");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static get observedAttributes() {
|
|
67
|
-
return ["markdown"];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
71
|
-
if (name === "markdown") {
|
|
72
|
-
this.markdown = newValue || "";
|
|
73
|
-
this.rerender();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
57
|
/**
|
|
78
58
|
* Set custom renderers for specific token types
|
|
79
59
|
*
|
|
@@ -118,14 +98,6 @@ export default class Markdown extends LightComponent {
|
|
|
118
98
|
}
|
|
119
99
|
}
|
|
120
100
|
|
|
121
|
-
protected onConnected() {
|
|
122
|
-
// Get initial value from attribute
|
|
123
|
-
const markdownAttr = this.getAttribute("markdown");
|
|
124
|
-
if (markdownAttr) {
|
|
125
|
-
this.markdown = markdownAttr;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
101
|
/**
|
|
130
102
|
* Convert marked tokens to WSX JSX elements
|
|
131
103
|
*/
|
|
@@ -223,10 +195,7 @@ export default class Markdown extends LightComponent {
|
|
|
223
195
|
return html;
|
|
224
196
|
});
|
|
225
197
|
return (
|
|
226
|
-
<wsx-marked-list
|
|
227
|
-
ordered={listToken.ordered ? "true" : "false"}
|
|
228
|
-
items={JSON.stringify(items)}
|
|
229
|
-
/>
|
|
198
|
+
<wsx-marked-list ordered={listToken.ordered ? "true" : "false"} items={items} />
|
|
230
199
|
);
|
|
231
200
|
}
|
|
232
201
|
|