| @@ -86,14 +86,9 @@ struct MarkdownView: View { |
| 86 | 86 | } |
| 87 | 87 | if trimmed.hasPrefix("- ") || trimmed.hasPrefix("* ") || trimmed.hasPrefix("+ ") { |
| 88 | 88 | var items: [String] = [] |
| 89 | | while let next = lines.first?.trimmingCharacters(in: .whitespaces) { |
| 90 | | if next.hasPrefix("- ") || next.hasPrefix("* ") || next.hasPrefix("+ ") { |
| 91 | | items.append(String(next.dropFirst(2))) |
| 92 | | } else if Self.continuesItem(lines) { |
| 93 | | items[items.count - 1] += " " + next |
| 94 | | } else { |
| 95 | | break |
| 96 | | } |
| 89 | while let next = lines.first?.trimmingCharacters(in: .whitespaces), |
| 90 | next.hasPrefix("- ") || next.hasPrefix("* ") || next.hasPrefix("+ ") { |
| 91 | items.append(String(next.dropFirst(2))) |
| 97 | 92 | lines = lines.dropFirst() |
| 98 | 93 | } |
| 99 | 94 | blocks.append(.bullet(items)) |
| @@ -101,14 +96,9 @@ struct MarkdownView: View { |
| 101 | 96 | } |
| 102 | 97 | if trimmed.range(of: #"^\d+\. "#, options: .regularExpression) != nil { |
| 103 | 98 | var items: [String] = [] |
| 104 | | while let next = lines.first?.trimmingCharacters(in: .whitespaces) { |
| 105 | | if let range = next.range(of: #"^\d+\. "#, options: .regularExpression) { |
| 106 | | items.append(String(next[range.upperBound...])) |
| 107 | | } else if Self.continuesItem(lines) { |
| 108 | | items[items.count - 1] += " " + next |
| 109 | | } else { |
| 110 | | break |
| 111 | | } |
| 99 | while let next = lines.first?.trimmingCharacters(in: .whitespaces), |
| 100 | let range = next.range(of: #"^\d+\. "#, options: .regularExpression) { |
| 101 | items.append(String(next[range.upperBound...])) |
| 112 | 102 | lines = lines.dropFirst() |
| 113 | 103 | } |
| 114 | 104 | blocks.append(.ordered(items)) |
| @@ -150,19 +140,6 @@ struct MarkdownView: View { |
| 150 | 140 | return blocks |
| 151 | 141 | } |
| 152 | 142 | |
| 153 | | /// A line that wraps the list item above it: anything but a blank line or |
| 154 | | /// the start of another block, indented or not, as in CommonMark. |
| 155 | | private static func continuesItem(_ lines: ArraySlice<String>) -> Bool { |
| 156 | | guard let line = lines.first?.trimmingCharacters(in: .whitespaces), !line.isEmpty |
| 157 | | else { return false } |
| 158 | | let startsBlock = line.hasPrefix("#") || line.hasPrefix("```") || line.hasPrefix(">") |
| 159 | | || line.hasPrefix("- ") || line.hasPrefix("* ") || line.hasPrefix("+ ") |
| 160 | | || line == "---" || line == "***" || line == "___" |
| 161 | | || line.range(of: #"^\d+\. "#, options: .regularExpression) != nil |
| 162 | | || tableStart(lines) != nil |
| 163 | | return !startsBlock |
| 164 | | } |
| 165 | | |
| 166 | 143 | // MARK: - Tables |
| 167 | 144 | |
| 168 | 145 | /// A table begins where a row of cells is followed by a separator row with the |
| @@ -247,7 +224,6 @@ struct MarkdownView: View { |
| 247 | 224 | HStack(alignment: .firstTextBaseline, spacing: 8) { |
| 248 | 225 | Text("•") |
| 249 | 226 | Self.inline(item, linkOptions: linkOptions) |
| 250 | | .fixedSize(horizontal: false, vertical: true) |
| 251 | 227 | } |
| 252 | 228 | } |
| 253 | 229 | } |
| @@ -257,7 +233,6 @@ struct MarkdownView: View { |
| 257 | 233 | HStack(alignment: .firstTextBaseline, spacing: 8) { |
| 258 | 234 | Text("\(index + 1).").monospacedDigit() |
| 259 | 235 | Self.inline(item, linkOptions: linkOptions) |
| 260 | | .fixedSize(horizontal: false, vertical: true) |
| 261 | 236 | } |
| 262 | 237 | } |
| 263 | 238 | } |