import Foundation func isTableLine(_ line: String) -> Bool { line.hasPrefix("|") && line.hasSuffix("|") } func parseTableRow(_ line: String) -> [String] { line .split(separator: "|", omittingEmptySubsequences: false) .dropFirst() .dropLast() .map { String($0).trimmingCharacters(in: .whitespaces) } } func parseOrgTableSeparatorRow(_ line: String) -> [String] { var content = line.trimmingCharacters(in: .whitespaces) if content.hasPrefix("|") { content.removeFirst() } if content.hasSuffix("|") { content.removeLast() } return content .split(separator: "+", omittingEmptySubsequences: false) .map { String($0).trimmingCharacters(in: .whitespaces) } } func isTableSeparatorCell(_ cell: String) -> Bool { tableAlignment(for: cell) != nil } func tableAlignment(for cell: String) -> String? { let trimmed = cell.trimmingCharacters(in: .whitespaces) guard !trimmed.isEmpty else { return nil } let core = trimmed.replacingOccurrences(of: ":", with: "") guard !core.isEmpty, core.allSatisfy({ $0 == "-" || $0 == "+" }) else { return nil } let isLeftAligned = trimmed.hasPrefix(":") let isRightAligned = trimmed.hasSuffix(":") switch (isLeftAligned, isRightAligned) { case (true, true): return "center" case (true, false): return "left" case (false, true): return "right" case (false, false): return "" } }