Let's fix the sub elements in lists: <!DOCTYPE html> <html lang="en"> <head> <meta…
- User
Let's fix the sub elements in lists:
html, body { height: 100%; } body { background-color: #1e1e1e; color: #cccccc; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; display: flex; flex-direction: column; } header { background-color: #252526; padding: 15px 20px; display: flex; align-items: center; justify-content: space-between; font-size: 1.5rem; font-weight: bold; border-bottom: 1px solid #333; position: relative; } /* Tabs for Mobile */ .tabs { display: none; /* Hidden by default, shown on mobile */ } .tabs button { background: none; border: none; color: #cccccc; padding: 10px 15px; cursor: pointer; font-size: 1rem; transition: background-color 0.3s; } .tabs button.active, .tabs button:hover { background-color: #3a3a3a; border-radius: 4px; } .container { flex: 1; display: flex; overflow: hidden; } .editor, .preview { flex: 1; padding: 20px; overflow: auto; } .editor { background-color: #1e1e1e; border-right: 1px solid #333; display: flex; flex-direction: column; } .editor textarea { width: 100%; height: 100%; background-color: #1e1e1e; color: #cccccc; border: none; resize: none; font-family: 'Courier New', Courier, monospace; font-size: 1rem; outline: none; } .error { color: #e74c3c; margin-top: 10px; font-size: 0.9rem; display: none; } .preview { background-color: #2d2d2d; } /* Scrollbar styling for WebKit */ ::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-track { background: #1e1e1e; } ::-webkit-scrollbar-thumb { background-color: #555; border-radius: 4px; } /* Responsive Design */ @media (max-width: 768px) { .container { flex-direction: column; } .editor, .preview { flex: 1; /* Allow flex items to grow */ display: none; /* Hide both by default */ height: 100%; /* Ensure they can take full height when displayed */ } .editor.active, .preview.active { display: flex; flex-direction: column; } .editor { border-right: none; border-bottom: 1px solid #333; } .tabs { display: flex; } .error { display: block; } } </style><script> const textarea = document.getElementById('code'); const previewFrame = document.getElementById('previewFrame'); const errorMessage = document.getElementById('error-message'); /** * Compiler Function: * Transforms custom syntax into standard HTML. * Supports: * - Tag definitions (e.g., h1{Hello}) * - Attributes and IDs (e.g., button[role="button"]#click-me{Click Me}) * - Nesting with '>' (e.g., div>p{Text}) * - Sibling with '+' (e.g., h1{Title}+p{Subtitle}) * - Repetition with '*' (e.g., p{&index;. Hey}*5) */ function compileToHTML(customCode) { const lines = customCode.split('\n').map(line => line.trim()).filter(line => line !== ''); let html = ''; let stack = []; try { lines.forEach(line => { html += parseLine(line, stack); }); // Close any remaining open tags while (stack.length > 0) { const tag = stack.pop(); html += `</${tag}>\n`; } return { html, errors: [] }; } catch (error) { return { html: '', errors: [error.message] }; } } /** * Parses a single line of custom syntax and returns the HTML. * Updates the stack based on nesting. * @param {string} line - A line of custom code. * @param {Array} stack - The current stack of open tags. * @returns {string} - The compiled HTML string. */ function parseLine(line, stack) { let html = ''; let tokens = line.split('>'); let parents = []; for (let i = 0; i < tokens.length; i++) { let token = tokens[i].trim(); let { tag, attributes, id, content, repeat } = parseElement(token); let attrString = ''; if (attributes) attrString += attributes; if (id) attrString += ` id="${id}"`; // Generate HTML based on repetition if (repeat > 1) { for (let j = 1; j <= repeat; j++) { let finalContent = content.replace(/&index;/g, j); html += `<${tag}${attrString}>${finalContent}</${tag}>\n`; } } else { if (i < tokens.length - 1) { // Not the last token, so it's a parent html += `<${tag}${attrString}>\n`; stack.push(tag); } else { // Last token, so it's an element that can be closed immediately if (content) { html += `<${tag}${attrString}>${content}</${tag}>\n`; } else { html += `<${tag}${attrString}></${tag}>\n`; } } } } return html; } /** * Parses an element definition from the custom syntax. * @param {string} token - A token from the custom code. * @returns {Object} - Parsed element details. */ function parseElement(token) { // Regex to match the element definition with optional attributes, ID, content, and repetition // Example matches: // div>p{&index;. Hey}*5 // button[role="button"]#click-me{Click Me} const regex = /^(\w+)(?:\[(.*?)\])?(?:#([\w-]+))?(?:\{([^}]*)\})?(?:\*(\d+))?$/; const match = token.match(regex); if (!match) { throw new Error(`Invalid syntax near "${token}".`); } const [ , tag, attrs, id, content, repeat ] = match; let attributes = ''; if (attrs) { // Attributes are expected to be in key="value" format, separated by spaces const attrRegex = /(\w+)="([^"]+)"/g; let attrMatch; while ((attrMatch = attrRegex.exec(attrs)) !== null) { const [ , attrName, attrValue ] = attrMatch; attributes += ` ${attrName}="${attrValue}"`; } if (attributes.trim() === '') { throw new Error(`Attributes must be in the format key="value".`); } } const element = { tag, attributes, id, content: content || '', repeat: repeat ? parseInt(repeat) : 1 }; return element; } /** * Updates the preview iframe based on the compiled HTML. */ function updatePreview() { const customCode = textarea.value; const { html, errors } = compileToHTML(customCode); if (errors.length > 0) { errorMessage.textContent = errors.join(' | '); errorMessage.style.display = 'block'; previewFrame.srcdoc = ''; // Clear preview if there are errors } else { errorMessage.textContent = ''; errorMessage.style.display = 'none'; // Wrap with basic HTML structure and custom dark theme const fullHTML = ` - Assistant