diff --git a/css/markdown.css b/css/markdown.css index 77fd681..0abf070 100644 --- a/css/markdown.css +++ b/css/markdown.css @@ -3,6 +3,8 @@ color: var(--md-text, #333); line-height: 1.6; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + --checkbox-size: 1.2em; + --checkbox-margin: 0.5em; } .mdrender h1, @@ -51,10 +53,24 @@ } .mdrender blockquote { - border-left: 4px solid var(--md-header, #2c3e50); - padding-left: 1rem; - margin: 1rem 0; - color: var(--md-blockquote, #666); + border-left: 4px solid var(--md-blockquote-border, #ddd); + margin: 1em 0; + padding: 0.5em 1em; + color: var(--md-blockquote-text, #666); + background-color: var(--md-blockquote-bg, rgba(0, 0, 0, 0.05)); +} + +.mdrender blockquote blockquote { + margin-left: 0.5em; + border-left-color: var(--md-blockquote-nested-border, #999); +} + +.mdrender blockquote blockquote blockquote { + border-left-color: var(--md-blockquote-nested-2-border, #666); +} + +.mdrender blockquote blockquote blockquote blockquote { + border-left-color: var(--md-blockquote-nested-3-border, #333); } .mdrender ul, @@ -114,13 +130,34 @@ } /* Task Lists */ -.mdrender .task-list-item { - list-style-type: none; - margin-left: -1.5rem; +.mdrender ul.task-list { + list-style: none; + padding-left: 0; } -.mdrender .task-list-item input[type="checkbox"] { - margin-right: 0.5rem; +.mdrender .task-list-item { + display: flex; + align-items: flex-start; + margin: 0.5em 0; + line-height: 1.4; +} + +.mdrender .task-list-item-checkbox { + width: var(--checkbox-size); + height: var(--checkbox-size); + margin: 0.1em var(--checkbox-margin) 0 0; + flex-shrink: 0; +} + +.mdrender .task-list-item-text { + flex: 1; + min-width: 0; +} + +/* Nested task lists */ +.mdrender .task-list .task-list { + margin-top: 0.5em; + margin-left: var(--checkbox-size); } /* Footnotes */ diff --git a/js/renderer.js b/js/renderer.js index 8cc963d..14479ec 100644 --- a/js/renderer.js +++ b/js/renderer.js @@ -12,11 +12,11 @@ class MDRenderer { image: /!\[(.+?)\]\((.+?)(?:\s+"(.+?)")?\)/g, list: /^(\s*)[*-]\s(.+)$/gm, orderedList: /^(\s*)\d+\.\s(.+)$/gm, - blockquote: /^>\s(.+)$/gm, + blockquote: /^((?:\s*>+\s*)+)(.+)$/gm, horizontalRule: /^([-*_])\1{2,}$/gm, table: /^\|(.+)\|$/gm, tableDelimiter: /^\|(?:[-:]+[-| :]*)\|$/gm, - taskList: /^(\s*)-\s\[([ x])\]\s(.+)$/gm, + taskList: /^(\s*)-\s+\[([ x])\]\s+(.+)$/gm, superscript: /\^(.+?)\^/g, subscript: /~(.+?)~/g, highlight: /==(.+?)==/g, @@ -56,12 +56,16 @@ class MDRenderer { // Convert code blocks first to prevent interference html = this.renderCodeBlocks(html); + // Process blockquotes first to handle nesting + html = this.renderBlockquotes(html); + + // Then process task lists + html = this.renderTaskLists(html); + // Convert block elements html = this.renderHorizontalRules(html); - html = this.renderBlockquotes(html); html = this.renderHeadings(html); html = this.renderTables(html); - html = this.renderTaskLists(html); html = this.renderLists(html); html = this.renderOrderedLists(html); html = this.renderDefinitions(html); @@ -186,7 +190,118 @@ class MDRenderer { } renderBlockquotes(text) { - return text.replace(this.rules.blockquote, '
$1'); + const lines = text.split('\n'); + const result = []; + let inBlockquote = false; + let currentContent = []; + let currentLevel = 0; + + function processBlockquote(content, level) { + if (content.length === 0) return ''; + const innerContent = content.join('\n').trim(); + let html = innerContent; + for (let i = 0; i < level; i++) { + html = `
${html}`; + } + return html; + } + + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; + const match = line.match(/^(>+)?\s*(.*)$/); + + if (match) { + const [, quotes, content] = match; + const level = quotes ? quotes.length : 0; + + if (level > 0) { + if (!inBlockquote) { + inBlockquote = true; + currentLevel = level; + } + + if (level !== currentLevel) { + // Process previous blockquote + result.push(processBlockquote(currentContent, currentLevel)); + currentContent = []; + currentLevel = level; + } + + currentContent.push(content.trim()); + } else { + if (inBlockquote) { + // End of blockquote + result.push(processBlockquote(currentContent, currentLevel)); + currentContent = []; + inBlockquote = false; + } + result.push(line); + } + } + } + + // Process any remaining blockquote + if (inBlockquote && currentContent.length > 0) { + result.push(processBlockquote(currentContent, currentLevel)); + } + + return result.join('\n'); + } + + renderTaskLists(text) { + const processedLines = []; + const lines = text.split('\n'); + let currentList = null; + let currentIndent = 0; + + for (let line of lines) { + const taskMatch = line.match(/^(\s*)-\s+\[([ x])\]\s+(.+)$/); + + if (taskMatch) { + const [, indent, checked, content] = taskMatch; + const indentLevel = indent.length; + + const checkbox = ``; + const listItem = `