Sources/OrgSwift/Lists.swift
17 lines · 640 bytes
1import Foundation
2
3func orderedListItem(in line: String) -> String? {
4 guard let match = line.firstMatch(of: /^(\d+)\.\s+(.+)$/) else { return nil }
5 return String(match.2)
6}
7
8/// True if a line (already outdented to its level) starts a list item at column 0.
9func isListMarkerLine(_ line: String) -> Bool {
10 line.hasPrefix("- ") || line.hasPrefix("+ ") || orderedListItem(in: line) != nil
11}
12
13func isIndentedContinuationLine(_ line: String) -> Bool {
14 guard !line.trimmingCharacters(in: .whitespaces).isEmpty else { return false }
15 guard let first = line.first else { return false }
16 return first == " " || first == "\t"
17}