chore: added style changes
2d3cd675
4 file(s) · +38 −13
| 13 | 13 | case heading3(String) |
|
| 14 | 14 | case listItem(String) |
|
| 15 | 15 | case quote(String) |
|
| 16 | - | case preformattedToggle(alt: String) |
|
| 17 | - | case preformatted(String) |
|
| 16 | + | case preformattedBlock(String, alt: String) |
|
| 18 | 17 | } |
| 9 | 9 | static func parse(_ content: String, baseURL: String) -> [TitanLine] { |
|
| 10 | 10 | var lines: [TitanLine] = [] |
|
| 11 | 11 | var inPreformatted = false |
|
| 12 | + | var preformattedLines: [String] = [] |
|
| 13 | + | var preformattedAlt = "" |
|
| 12 | 14 | ||
| 13 | 15 | for line in content.components(separatedBy: .newlines) { |
|
| 14 | 16 | if line.hasPrefix("```") { |
|
| 17 | + | if inPreformatted { |
|
| 18 | + | // End of preformatted block - emit the collected lines |
|
| 19 | + | let blockContent = preformattedLines.joined(separator: "\n") |
|
| 20 | + | lines.append(.preformattedBlock(blockContent, alt: preformattedAlt)) |
|
| 21 | + | preformattedLines = [] |
|
| 22 | + | preformattedAlt = "" |
|
| 23 | + | } else { |
|
| 24 | + | // Start of preformatted block |
|
| 25 | + | preformattedAlt = String(line.dropFirst(3)) |
|
| 26 | + | } |
|
| 15 | 27 | inPreformatted.toggle() |
|
| 16 | - | let alt = String(line.dropFirst(3)) |
|
| 17 | - | lines.append(.preformattedToggle(alt: alt)) |
|
| 18 | 28 | continue |
|
| 19 | 29 | } |
|
| 20 | 30 | ||
| 21 | 31 | if inPreformatted { |
|
| 22 | - | lines.append(.preformatted(line)) |
|
| 32 | + | preformattedLines.append(line) |
|
| 23 | 33 | continue |
|
| 24 | 34 | } |
|
| 25 | 35 | ||
| 40 | 50 | } else { |
|
| 41 | 51 | lines.append(.text(line)) |
|
| 42 | 52 | } |
|
| 53 | + | } |
|
| 54 | + | ||
| 55 | + | // Handle unclosed preformatted block |
|
| 56 | + | if !preformattedLines.isEmpty { |
|
| 57 | + | let blockContent = preformattedLines.joined(separator: "\n") |
|
| 58 | + | lines.append(.preformattedBlock(blockContent, alt: preformattedAlt)) |
|
| 43 | 59 | } |
|
| 44 | 60 | ||
| 45 | 61 | return lines |
|
| 137 | 137 | } |
|
| 138 | 138 | ||
| 139 | 139 | private func navigateTo(_ url: String) { |
|
| 140 | + | // Check if this is an external URL (http, https, mailto) |
|
| 141 | + | if let urlObj = URL(string: url) { |
|
| 142 | + | let scheme = urlObj.scheme?.lowercased() ?? "" |
|
| 143 | + | if scheme == "http" || scheme == "https" || scheme == "mailto" { |
|
| 144 | + | UIApplication.shared.open(urlObj) |
|
| 145 | + | return |
|
| 146 | + | } |
|
| 147 | + | } |
|
| 148 | + | ||
| 140 | 149 | if historyIndex < history.count - 1 { |
|
| 141 | 150 | history = Array(history.prefix(historyIndex + 1)) |
|
| 142 | 151 | } |
| 43 | 43 | } |
|
| 44 | 44 | } |
|
| 45 | 45 | .foregroundColor(.orange) |
|
| 46 | + | .padding(.vertical, 6) |
|
| 46 | 47 | ||
| 47 | 48 | case .heading1(let text): |
|
| 48 | 49 | Text(text) |
|
| 76 | 77 | .foregroundColor(.secondary) |
|
| 77 | 78 | .padding(.leading, 12) |
|
| 78 | 79 | ||
| 79 | - | case .preformattedToggle: |
|
| 80 | - | EmptyView() |
|
| 81 | - | ||
| 82 | - | case .preformatted(let text): |
|
| 83 | - | Text(text) |
|
| 84 | - | .font(.system(.caption, design: .monospaced)) |
|
| 85 | - | .foregroundColor(.secondary) |
|
| 86 | - | .padding(.leading, 8) |
|
| 80 | + | case .preformattedBlock(let text, _): |
|
| 81 | + | ScrollView(.horizontal, showsIndicators: false) { |
|
| 82 | + | Text(text) |
|
| 83 | + | .font(.system(.caption, design: .monospaced)) |
|
| 84 | + | .foregroundColor(.secondary) |
|
| 85 | + | .fixedSize(horizontal: true, vertical: false) |
|
| 86 | + | } |
|
| 87 | + | .padding(.vertical, 4) |
|
| 87 | 88 | } |
|
| 88 | 89 | } |
|
| 89 | 90 | } |
|