@duskmoon-dev/el-markdown-input 1.5.4 → 1.5.6
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 -0
- package/dist/cjs/index.js +73 -5
- package/dist/cjs/index.js.map +6 -6
- package/dist/cjs/register.js +73 -5
- package/dist/cjs/register.js.map +6 -6
- package/dist/esm/index.js +73 -5
- package/dist/esm/index.js.map +6 -6
- package/dist/esm/register.js +73 -5
- package/dist/esm/register.js.map +6 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/css.d.ts.map +1 -1
- package/dist/types/element.d.ts.map +1 -1
- package/dist/types/render.d.ts.map +1 -1
- package/package.json +5 -3
package/dist/esm/index.js
CHANGED
|
@@ -45,7 +45,7 @@ var sanitizeSchema;
|
|
|
45
45
|
var init_sanitize_schema = __esm(() => {
|
|
46
46
|
sanitizeSchema = deepMergeSchemas(defaultSchema, {
|
|
47
47
|
attributes: {
|
|
48
|
-
span: ["className", "style"],
|
|
48
|
+
span: ["className", "style", "ariaHidden"],
|
|
49
49
|
code: ["className"],
|
|
50
50
|
input: ["type", "checked", "disabled"],
|
|
51
51
|
math: ["xmlns", "display"],
|
|
@@ -92,12 +92,57 @@ __export(exports_render, {
|
|
|
92
92
|
renderMermaidBlocks: () => renderMermaidBlocks,
|
|
93
93
|
renderMarkdown: () => renderMarkdown
|
|
94
94
|
});
|
|
95
|
+
function renderFrontMatter() {
|
|
96
|
+
return (tree) => {
|
|
97
|
+
if (tree.type === "root" && tree.children) {
|
|
98
|
+
tree.children = tree.children.map((node) => node.type === "yaml" ? { type: "code", lang: "yaml", value: node.value } : node);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function isSupportedColor(value) {
|
|
103
|
+
if (/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(value))
|
|
104
|
+
return true;
|
|
105
|
+
const rgb = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.exec(value);
|
|
106
|
+
if (rgb)
|
|
107
|
+
return rgb.slice(1).every((channel) => Number(channel) <= 255);
|
|
108
|
+
const hsl = /^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/.exec(value);
|
|
109
|
+
return Boolean(hsl && Number(hsl[1]) <= 360 && Number(hsl[2]) <= 100 && Number(hsl[3]) <= 100);
|
|
110
|
+
}
|
|
111
|
+
function addColorChips() {
|
|
112
|
+
return (tree) => {
|
|
113
|
+
appendColorChips(tree);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function appendColorChips(node) {
|
|
117
|
+
if (!node.children)
|
|
118
|
+
return;
|
|
119
|
+
for (const child of node.children) {
|
|
120
|
+
const text = child.children?.length === 1 ? child.children[0] : undefined;
|
|
121
|
+
const color = node.tagName !== "pre" && child.type === "element" && child.tagName === "code" && text?.type === "text" ? text.value : undefined;
|
|
122
|
+
if (color && isSupportedColor(color)) {
|
|
123
|
+
child.children?.push({
|
|
124
|
+
type: "element",
|
|
125
|
+
tagName: "span",
|
|
126
|
+
properties: {
|
|
127
|
+
className: ["color-chip"],
|
|
128
|
+
style: `--color-chip: ${color}`,
|
|
129
|
+
ariaHidden: "true"
|
|
130
|
+
},
|
|
131
|
+
children: []
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
appendColorChips(child);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
95
138
|
async function buildProcessor() {
|
|
96
139
|
const [
|
|
97
140
|
{ unified },
|
|
98
141
|
{ default: remarkParse },
|
|
142
|
+
{ default: remarkFrontmatter },
|
|
99
143
|
{ default: remarkGfm },
|
|
100
144
|
{ default: remarkMath },
|
|
145
|
+
{ default: remarkBreaks },
|
|
101
146
|
{ default: remarkRehype },
|
|
102
147
|
{ default: rehypeKatex },
|
|
103
148
|
{ default: rehypePrismPlus },
|
|
@@ -106,15 +151,17 @@ async function buildProcessor() {
|
|
|
106
151
|
] = await Promise.all([
|
|
107
152
|
import("unified"),
|
|
108
153
|
import("remark-parse"),
|
|
154
|
+
import("remark-frontmatter"),
|
|
109
155
|
import("remark-gfm"),
|
|
110
156
|
import("remark-math"),
|
|
157
|
+
import("remark-breaks"),
|
|
111
158
|
import("remark-rehype"),
|
|
112
159
|
import("rehype-katex"),
|
|
113
160
|
import("rehype-prism-plus"),
|
|
114
161
|
import("rehype-sanitize"),
|
|
115
162
|
import("rehype-stringify")
|
|
116
163
|
]);
|
|
117
|
-
return unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkRehype, { allowDangerousHtml: false }).use(rehypeKatex).use(rehypePrismPlus, { ignoreMissing: true }).use(rehypeSanitize, sanitizeSchema).use(rehypeStringify);
|
|
164
|
+
return unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(renderFrontMatter).use(remarkGfm).use(remarkMath).use(remarkBreaks).use(remarkRehype, { allowDangerousHtml: false }).use(rehypeKatex).use(rehypePrismPlus, { ignoreMissing: true }).use(addColorChips).use(rehypeSanitize, sanitizeSchema).use(rehypeStringify);
|
|
118
165
|
}
|
|
119
166
|
function getProcessor() {
|
|
120
167
|
if (!processorPromise) {
|
|
@@ -402,6 +449,17 @@ var elementStyles = css`
|
|
|
402
449
|
flex-shrink: 0;
|
|
403
450
|
}
|
|
404
451
|
|
|
452
|
+
.preview-body .color-chip {
|
|
453
|
+
display: inline-block;
|
|
454
|
+
width: 0.75em;
|
|
455
|
+
height: 0.75em;
|
|
456
|
+
margin-left: 0.35em;
|
|
457
|
+
vertical-align: -0.05em;
|
|
458
|
+
background-color: var(--color-chip);
|
|
459
|
+
border: 1px solid var(--md-border);
|
|
460
|
+
border-radius: 0.2em;
|
|
461
|
+
}
|
|
462
|
+
|
|
405
463
|
/* ── Preview skeleton (shown while render pipeline loads) ──────────── */
|
|
406
464
|
.preview-skeleton {
|
|
407
465
|
display: flex;
|
|
@@ -1132,6 +1190,16 @@ class ElDmMarkdownInput extends BaseElement {
|
|
|
1132
1190
|
this.#internals = this.attachInternals();
|
|
1133
1191
|
this.attachStyles([elementStyles, markdownBodySheet]);
|
|
1134
1192
|
}
|
|
1193
|
+
#resolveValue(fallback = "") {
|
|
1194
|
+
const value = this.value;
|
|
1195
|
+
if (typeof value === "string") {
|
|
1196
|
+
return value;
|
|
1197
|
+
}
|
|
1198
|
+
if (Array.isArray(value) && value.every((part) => typeof part === "string" || typeof part === "number")) {
|
|
1199
|
+
return value.join("");
|
|
1200
|
+
}
|
|
1201
|
+
return this.getAttribute("value") ?? fallback;
|
|
1202
|
+
}
|
|
1135
1203
|
connectedCallback() {
|
|
1136
1204
|
super.connectedCallback();
|
|
1137
1205
|
}
|
|
@@ -1148,7 +1216,7 @@ class ElDmMarkdownInput extends BaseElement {
|
|
|
1148
1216
|
this.#cacheDOMRefs();
|
|
1149
1217
|
this.#attachEventHandlers();
|
|
1150
1218
|
this.#initHighlight();
|
|
1151
|
-
const initVal = this
|
|
1219
|
+
const initVal = this.#resolveValue();
|
|
1152
1220
|
if (this.#textarea) {
|
|
1153
1221
|
this.#textarea.value = initVal;
|
|
1154
1222
|
this.#syncFormValue();
|
|
@@ -1172,7 +1240,7 @@ class ElDmMarkdownInput extends BaseElement {
|
|
|
1172
1240
|
if (attachBtn) {
|
|
1173
1241
|
attachBtn.disabled = ta.disabled || ta.readOnly;
|
|
1174
1242
|
}
|
|
1175
|
-
const propVal = this.value
|
|
1243
|
+
const propVal = this.#resolveValue(ta.value);
|
|
1176
1244
|
if (propVal !== ta.value) {
|
|
1177
1245
|
ta.value = propVal;
|
|
1178
1246
|
this.#syncFormValue();
|
|
@@ -1910,5 +1978,5 @@ export {
|
|
|
1910
1978
|
ElDmMarkdownInput
|
|
1911
1979
|
};
|
|
1912
1980
|
|
|
1913
|
-
//# debugId=
|
|
1981
|
+
//# debugId=A55F11AEE048BDBA64756E2164756E21
|
|
1914
1982
|
//# sourceMappingURL=index.js.map
|