diff --git a/MarkdownViewer/ContentView.swift b/MarkdownViewer/ContentView.swift index 5500be4..15d8da0 100644 --- a/MarkdownViewer/ContentView.swift +++ b/MarkdownViewer/ContentView.swift @@ -14,12 +14,6 @@ struct ContentView: View { } .padding() - Button("Test with Sample Content") { - markdownContent = "# Test\n\nThis is **test** content." - print("Set test content: \(markdownContent)") - } - .padding() - if let url = selectedFileURL { Text("File: \(url.lastPathComponent)") .foregroundColor(.secondary) diff --git a/MarkdownViewer/MarkdownRenderer.swift b/MarkdownViewer/MarkdownRenderer.swift index ea680b1..03e4ce8 100644 --- a/MarkdownViewer/MarkdownRenderer.swift +++ b/MarkdownViewer/MarkdownRenderer.swift @@ -77,6 +77,10 @@ struct MarkdownRenderer: NSViewRepresentable { let codeRegex = try! NSRegularExpression(pattern: "`([^`]+)`", options: []) html = codeRegex.stringByReplacingMatches(in: html, options: [], range: NSRange(location: 0, length: html.count), withTemplate: "$1") + // Handle horizontal rules (-- on its own line) + let hrRegex = try! NSRegularExpression(pattern: "^--$", options: [.anchorsMatchLines]) + html = hrRegex.stringByReplacingMatches(in: html, options: [], range: NSRange(location: 0, length: html.count), withTemplate: "
") + // Handle links let linkRegex = try! NSRegularExpression(pattern: "\\[([^\\]]+)\\]\\(([^\\)]+)\\)", options: []) html = linkRegex.stringByReplacingMatches(in: html, options: [], range: NSRange(location: 0, length: html.count), withTemplate: "$1") @@ -88,8 +92,8 @@ struct MarkdownRenderer: NSViewRepresentable { if trimmed.isEmpty { return "" } - // Don't wrap headers in paragraphs - if trimmed.hasPrefix("" { return trimmed.replacingOccurrences(of: "\n", with: "
") } return "

" + trimmed.replacingOccurrences(of: "\n", with: "
") + "

" @@ -140,6 +144,11 @@ struct MarkdownRenderer: NSViewRepresentable { em { font-style: italic; } + hr { + border: none; + border-top: 2px solid #eee; + margin: 24px 0; + }