diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-06-19 22:06:26 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-06-19 22:15:42 +0200 |
| commit | 647296d5a0799c2e9de05cd41b50bd161cdeac85 (patch) | |
| tree | 61dd769ceadba7f139d2c299119e6b1b86d849ab /Sources/NorgKit/Parsers/NorgParser.swift | |
| parent | c796b061f2d1a1da02c92b71d518af6cef16d33a (diff) | |
Diffstat (limited to 'Sources/NorgKit/Parsers/NorgParser.swift')
| -rw-r--r-- | Sources/NorgKit/Parsers/NorgParser.swift | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/Sources/NorgKit/Parsers/NorgParser.swift b/Sources/NorgKit/Parsers/NorgParser.swift index aad66f4..20a76a0 100644 --- a/Sources/NorgKit/Parsers/NorgParser.swift +++ b/Sources/NorgKit/Parsers/NorgParser.swift @@ -1,10 +1,8 @@ /// Parses a Norg document into a list of `NorgBlock`s. public enum NorgParser { - private enum Delimiter { case weak, strong, rule } - - private static let blockMarkers = ASCIIByteSet("*-~>") - private static let rangeableMarkers = ASCIIByteSet("$^:") + private static let blockMarkers = BlockScanner.blockMarkers + private static let rangeableMarkers = BlockScanner.rangeableMarkers private struct Source { let raw: [Substring] @@ -51,7 +49,7 @@ public enum NorgParser { // Delimiting modifiers (lines of two or more identical -, = or _). // All three are emitted as blocks: `___` renders as a rule, while // `---`/`===` are reset signals the tree fold consumes. - if let delimiter = delimiter(line) { + if let delimiter = BlockScanner.delimiter(line) { switch delimiter { case .rule: blocks.append(.horizontalRule(line: lineNo)) case .weak: blocks.append(.weakDelimiter(line: lineNo)) @@ -264,22 +262,10 @@ public enum NorgParser { // MARK: - Helpers - /// Identifies a delimiting-modifier line (two or more identical `-`, `=`, `_`). - private static func delimiter(_ s: Substring) -> Delimiter? { - guard s.count >= 2, let first = s.first, "-=_".contains(first), - s.allSatisfy({ $0 == first }) - else { return nil } - switch first { - case "-": return .weak - case "=": return .strong - default: return .rule - } - } - /// Whether a trimmed line starts a new block (used to break paragraphs). private static func isBlockStart(_ trimmed: Substring) -> Bool { if trimmed.hasPrefix("@") { return true } - if delimiter(trimmed) != nil { return true } + if BlockScanner.delimiter(trimmed) != nil { return true } if DetachedModifier.parse(trimmed[...], accepting: blockMarkers) != nil { return true } return DetachedModifier.parse(trimmed[...], accepting: rangeableMarkers) != nil } |