commit cd31cb58eb9b2eddf8e940d81fd555962cddea05
parent 38a76b0a13c7564fb579cb4a6511d60af4525282
Author: FIGBERT <figbert@figbert.com>
Date: Tue, 19 Jul 2022 14:19:28 -0700
Make code style sexier
Diffstat:
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/Sources/SwiftGemtext/SwiftGemtext.swift b/Sources/SwiftGemtext/SwiftGemtext.swift
@@ -16,19 +16,19 @@ struct Gemtext {
if line.starts(with: "```") {
lines.append(pre.getLineType())
pre = PreformattedState()
- } else {
- pre.lines.append(line)
+ continue
}
+
+ pre.lines.append(line)
} else {
if line.starts(with: "```") {
let alt = line.dropFirst(3).trimmingCharacters(in: .whitespacesAndNewlines)
- if alt.count > 0 {
- pre.alt = alt
- }
+ if alt.count > 0 { pre.alt = alt }
pre.active = true
- } else {
- lines.append(parsePlainLine(line))
+ continue
}
+
+ lines.append(parsePlainLine(line))
}
}
return lines
@@ -47,6 +47,7 @@ struct Gemtext {
let urlAndCaption = line.dropFirst(2).trimmingCharacters(in: .whitespacesAndNewlines)
let spaceDelim = urlAndCaption.firstIndex(of: " ")
let tabDelim = urlAndCaption.firstIndex(of: "\t")
+
var delim: String.Index
if spaceDelim != nil && tabDelim != nil {
delim = min(spaceDelim!, tabDelim!)
@@ -57,6 +58,7 @@ struct Gemtext {
} else {
return LineType.Link(URL(string: urlAndCaption)!, nil)
}
+
let url = URL(string: String(urlAndCaption[..<delim]))!
let caption = String(urlAndCaption[delim...]).trimmingCharacters(in: .whitespacesAndNewlines)
return LineType.Link(url, caption)