@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/README.md
CHANGED
|
@@ -5,6 +5,7 @@ A form-associated custom element providing a full-featured markdown editor.
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- **Write / Preview tabs** — switch between editing and rendered output
|
|
8
|
+
- **Rich preview** — highlighted YAML front matter, inline color chips, and soft line breaks
|
|
8
9
|
- **Syntax highlighting** — backdrop technique with Prism.js (lazy CDN load)
|
|
9
10
|
- **File upload** — drag-and-drop, clipboard paste, or file picker with progress
|
|
10
11
|
- **Autocomplete** — `@mention` and `#reference` with keyboard navigation
|
package/dist/cjs/index.js
CHANGED
|
@@ -61,7 +61,7 @@ var init_sanitize_schema = __esm(() => {
|
|
|
61
61
|
import_rehype_sanitize = require("rehype-sanitize");
|
|
62
62
|
sanitizeSchema = deepMergeSchemas(import_rehype_sanitize.defaultSchema, {
|
|
63
63
|
attributes: {
|
|
64
|
-
span: ["className", "style"],
|
|
64
|
+
span: ["className", "style", "ariaHidden"],
|
|
65
65
|
code: ["className"],
|
|
66
66
|
input: ["type", "checked", "disabled"],
|
|
67
67
|
math: ["xmlns", "display"],
|
|
@@ -108,12 +108,57 @@ __export(exports_render, {
|
|
|
108
108
|
renderMermaidBlocks: () => renderMermaidBlocks,
|
|
109
109
|
renderMarkdown: () => renderMarkdown
|
|
110
110
|
});
|
|
111
|
+
function renderFrontMatter() {
|
|
112
|
+
return (tree) => {
|
|
113
|
+
if (tree.type === "root" && tree.children) {
|
|
114
|
+
tree.children = tree.children.map((node) => node.type === "yaml" ? { type: "code", lang: "yaml", value: node.value } : node);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function isSupportedColor(value) {
|
|
119
|
+
if (/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(value))
|
|
120
|
+
return true;
|
|
121
|
+
const rgb = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.exec(value);
|
|
122
|
+
if (rgb)
|
|
123
|
+
return rgb.slice(1).every((channel) => Number(channel) <= 255);
|
|
124
|
+
const hsl = /^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/.exec(value);
|
|
125
|
+
return Boolean(hsl && Number(hsl[1]) <= 360 && Number(hsl[2]) <= 100 && Number(hsl[3]) <= 100);
|
|
126
|
+
}
|
|
127
|
+
function addColorChips() {
|
|
128
|
+
return (tree) => {
|
|
129
|
+
appendColorChips(tree);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function appendColorChips(node) {
|
|
133
|
+
if (!node.children)
|
|
134
|
+
return;
|
|
135
|
+
for (const child of node.children) {
|
|
136
|
+
const text = child.children?.length === 1 ? child.children[0] : undefined;
|
|
137
|
+
const color = node.tagName !== "pre" && child.type === "element" && child.tagName === "code" && text?.type === "text" ? text.value : undefined;
|
|
138
|
+
if (color && isSupportedColor(color)) {
|
|
139
|
+
child.children?.push({
|
|
140
|
+
type: "element",
|
|
141
|
+
tagName: "span",
|
|
142
|
+
properties: {
|
|
143
|
+
className: ["color-chip"],
|
|
144
|
+
style: `--color-chip: ${color}`,
|
|
145
|
+
ariaHidden: "true"
|
|
146
|
+
},
|
|
147
|
+
children: []
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
appendColorChips(child);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
111
154
|
async function buildProcessor() {
|
|
112
155
|
const [
|
|
113
156
|
{ unified },
|
|
114
157
|
{ default: remarkParse },
|
|
158
|
+
{ default: remarkFrontmatter },
|
|
115
159
|
{ default: remarkGfm },
|
|
116
160
|
{ default: remarkMath },
|
|
161
|
+
{ default: remarkBreaks },
|
|
117
162
|
{ default: remarkRehype },
|
|
118
163
|
{ default: rehypeKatex },
|
|
119
164
|
{ default: rehypePrismPlus },
|
|
@@ -122,15 +167,17 @@ async function buildProcessor() {
|
|
|
122
167
|
] = await Promise.all([
|
|
123
168
|
import("unified"),
|
|
124
169
|
import("remark-parse"),
|
|
170
|
+
import("remark-frontmatter"),
|
|
125
171
|
import("remark-gfm"),
|
|
126
172
|
import("remark-math"),
|
|
173
|
+
import("remark-breaks"),
|
|
127
174
|
import("remark-rehype"),
|
|
128
175
|
import("rehype-katex"),
|
|
129
176
|
import("rehype-prism-plus"),
|
|
130
177
|
import("rehype-sanitize"),
|
|
131
178
|
import("rehype-stringify")
|
|
132
179
|
]);
|
|
133
|
-
return unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkRehype, { allowDangerousHtml: false }).use(rehypeKatex).use(rehypePrismPlus, { ignoreMissing: true }).use(rehypeSanitize, sanitizeSchema).use(rehypeStringify);
|
|
180
|
+
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);
|
|
134
181
|
}
|
|
135
182
|
function getProcessor() {
|
|
136
183
|
if (!processorPromise) {
|
|
@@ -427,6 +474,17 @@ var elementStyles = import_el_base.css`
|
|
|
427
474
|
flex-shrink: 0;
|
|
428
475
|
}
|
|
429
476
|
|
|
477
|
+
.preview-body .color-chip {
|
|
478
|
+
display: inline-block;
|
|
479
|
+
width: 0.75em;
|
|
480
|
+
height: 0.75em;
|
|
481
|
+
margin-left: 0.35em;
|
|
482
|
+
vertical-align: -0.05em;
|
|
483
|
+
background-color: var(--color-chip);
|
|
484
|
+
border: 1px solid var(--md-border);
|
|
485
|
+
border-radius: 0.2em;
|
|
486
|
+
}
|
|
487
|
+
|
|
430
488
|
/* ── Preview skeleton (shown while render pipeline loads) ──────────── */
|
|
431
489
|
.preview-skeleton {
|
|
432
490
|
display: flex;
|
|
@@ -1157,6 +1215,16 @@ class ElDmMarkdownInput extends import_el_base2.BaseElement {
|
|
|
1157
1215
|
this.#internals = this.attachInternals();
|
|
1158
1216
|
this.attachStyles([elementStyles, markdownBodySheet]);
|
|
1159
1217
|
}
|
|
1218
|
+
#resolveValue(fallback = "") {
|
|
1219
|
+
const value = this.value;
|
|
1220
|
+
if (typeof value === "string") {
|
|
1221
|
+
return value;
|
|
1222
|
+
}
|
|
1223
|
+
if (Array.isArray(value) && value.every((part) => typeof part === "string" || typeof part === "number")) {
|
|
1224
|
+
return value.join("");
|
|
1225
|
+
}
|
|
1226
|
+
return this.getAttribute("value") ?? fallback;
|
|
1227
|
+
}
|
|
1160
1228
|
connectedCallback() {
|
|
1161
1229
|
super.connectedCallback();
|
|
1162
1230
|
}
|
|
@@ -1173,7 +1241,7 @@ class ElDmMarkdownInput extends import_el_base2.BaseElement {
|
|
|
1173
1241
|
this.#cacheDOMRefs();
|
|
1174
1242
|
this.#attachEventHandlers();
|
|
1175
1243
|
this.#initHighlight();
|
|
1176
|
-
const initVal = this
|
|
1244
|
+
const initVal = this.#resolveValue();
|
|
1177
1245
|
if (this.#textarea) {
|
|
1178
1246
|
this.#textarea.value = initVal;
|
|
1179
1247
|
this.#syncFormValue();
|
|
@@ -1197,7 +1265,7 @@ class ElDmMarkdownInput extends import_el_base2.BaseElement {
|
|
|
1197
1265
|
if (attachBtn) {
|
|
1198
1266
|
attachBtn.disabled = ta.disabled || ta.readOnly;
|
|
1199
1267
|
}
|
|
1200
|
-
const propVal = this.value
|
|
1268
|
+
const propVal = this.#resolveValue(ta.value);
|
|
1201
1269
|
if (propVal !== ta.value) {
|
|
1202
1270
|
ta.value = propVal;
|
|
1203
1271
|
this.#syncFormValue();
|
|
@@ -1930,5 +1998,5 @@ var MarkdownInputHook = {
|
|
|
1930
1998
|
}
|
|
1931
1999
|
};
|
|
1932
2000
|
|
|
1933
|
-
//# debugId=
|
|
2001
|
+
//# debugId=15221D1A0F3E2E4364756E2164756E21
|
|
1934
2002
|
//# sourceMappingURL=index.js.map
|