Skip to content

Commit defd680

Browse files
committed
🔤 ⚡ converter - convert also comments
1 parent 2fcec05 commit defd680

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

docs/components/converter.js.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ const NODE_TYPE = {
6464

6565
// Convert a parsed node to dd<el> code
6666
function nodeToDDE(node, options = {}, level = 0) {
67+
const tab= options.indent === "-1" ? "\t" : " ".repeat(options.indent);
68+
const indent = tab.repeat(level);
69+
const nextIndent = tab.repeat(level + 1);
70+
6771
const { nodeType } = node;
6872
// Handle text nodes
6973
if (nodeType === NODE_TYPE.TEXT) {
70-
const text = node.nodeValue;
74+
const text = el("i", { innerText: node.nodeValue }).textContent;
7175
if (!text.trim()) return null;
7276

7377
// Return as plain text or template string for longer text
@@ -78,15 +82,15 @@ function nodeToDDE(node, options = {}, level = 0) {
7882

7983
// Handle comment nodes
8084
if (nodeType === NODE_TYPE.COMMENT) {
81-
return null; // TODO: Skip comments?
85+
const text = node.nodeValue;
86+
if (!text.trim()) return null;
87+
return text.includes("\n")
88+
? [ "/*", ...text.trim().split("\n").map(l=> tab+l), "*/" ]
89+
: [ `// ${text}` ];
8290
}
8391

8492
// For element nodes
8593
if (nodeType === NODE_TYPE.ELEMENT) {
86-
const tab= options.indent === "-1" ? "\t" : " ".repeat(options.indent);
87-
const indent = tab.repeat(level);
88-
const nextIndent = tab.repeat(level + 1);
89-
9094
// Special case for SVG elements
9195
const isNS = node.tagName === "svg";
9296
const elFunction = isNS ? "elNS" : "el";
@@ -171,12 +175,14 @@ function nodeToDDE(node, options = {}, level = 0) {
171175
// Process children
172176
const children = [];
173177
for (const child of node.childNodes) {
174-
const childCode = nodeToDDE(child, options, level + 1);
175-
if (childCode) children.push(childCode);
178+
const childCode = nodeToDDE(child, options, level + 1);
179+
if (!childCode) continue;
180+
181+
children.push(childCode);
176182
}
177-
if(children.length===1 && node.childNodes[0].nodeType===NODE_TYPE.TEXT){
178-
const textContent= children.pop().slice(1, -1);
179-
attrs.unshift(`textContent: "${textContent}"`);
183+
if(node.childNodes.length===1 && node.childNodes[0].nodeType===NODE_TYPE.TEXT){
184+
const textContent= children.pop().slice(1, -1);
185+
attrs.unshift(`textContent: "${textContent}"`);
180186
}
181187

182188
// Build the element creation code
@@ -189,15 +195,16 @@ function nodeToDDE(node, options = {}, level = 0) {
189195
result += `, {\n${nextIndent}${attrs.join(`,\n${nextIndent}`)},\n${indent}}`;
190196
else
191197
result += `, { ${attrs.join(", ")} }`;
192-
} else if (children.length > 0) {
193-
result += ", null";
194198
}
195199

196200
// Add children if any
197201
if (children.length > 0) {
198-
result += `).append(\n${nextIndent}${children.join(`,\n${nextIndent}`)},\n${indent})`;
202+
const chs= children.map(ch=>
203+
Array.isArray(ch) ? ch.map(l=> nextIndent + l).join("\n") :
204+
nextIndent + ch + ",");
205+
result += `).append(\n${chs.join("\n")}\n${indent})`;
199206
} else {
200-
result += ")";
207+
result += ")";
201208
}
202209

203210
return result;

docs/components/ireland.html.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export function ireland({ src, exportName = "default", props = {} }) {
5555
import(path)
5656
.then(module => {
5757
const component = module[exportName];
58-
element.replaceWith(el(component, props, mark(id)));
58+
const content= el(component, props, mark(id));
59+
element.replaceWith(content);
60+
content.querySelectorAll("input, textarea, button")
61+
.forEach(el=> el.disabled= true);
5962
})
6063
.catch(console.error)
6164
);

docs/components/ireland.js.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export function loadIrelands(store) {
55
document.body.querySelectorAll("[data-dde-mark]").forEach(ireland => {
66
const { ddeMark }= ireland.dataset;
77
if(!store.has(ddeMark)) return;
8-
ireland.querySelectorAll("input").forEach(input => input.disabled = true);
98
const { path, exportName, props }= store.get(ddeMark);
109
import("./"+path).then(module => {
1110
ireland.replaceWith(el(module[exportName], props));

0 commit comments

Comments
 (0)