commit b9b038c11b02cfaa44fa42490de2195db05164fe
parent 91bcb08c483d74902578178012c9f591e991b8af
Author: FIGBERT <figbert@figbert.com>
Date: Tue, 20 Apr 2021 00:40:26 -0700
Prevent aborting run on link parse w/out caption
Diffstat:
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/Sources/SwiftGemtext/SwiftGemtext.swift b/Sources/SwiftGemtext/SwiftGemtext.swift
@@ -43,13 +43,13 @@ struct SwiftGemtext {
return LineType.Heading(level, line.dropFirst(level).trimmingCharacters(in: .whitespacesAndNewlines))
} else if line.starts(with: "=>") { // Link
let urlAndCaption = line.dropFirst(2).trimmingCharacters(in: .whitespacesAndNewlines)
- let delim = urlAndCaption.firstIndex(of: " ")!
- let url = URL(string: String(urlAndCaption[..<delim]))!
- let caption = urlAndCaption[delim...]
- if caption.count > 0 {
- return LineType.Link(url, String(caption))
+ let delim = urlAndCaption.firstIndex(of: " ")
+ if delim != nil {
+ let url = URL(string: String(urlAndCaption[..<delim!]))!
+ let caption = String(urlAndCaption[delim!...]).trimmingCharacters(in: .whitespacesAndNewlines)
+ return LineType.Link(url, caption)
} else {
- return LineType.Link(url, nil)
+ return LineType.Link(URL(string: urlAndCaption)!, nil)
}
} else if line.starts(with: "* ") { // Unordered List
return LineType.UnorderedList(line.dropFirst(2).trimmingCharacters(in: .whitespacesAndNewlines))