Skip to content

Commit 0202803

Browse files
Update markdown.swift
1 parent 50bd15a commit 0202803

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

Scripts/markdown.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
OVERVIEW: Convert Xcode Playground to markdown
55

6-
USAGE: cat Playgrounds/Example.playground/Contents.swift | ./Scripts/markdown.swift
6+
USAGE: cat Playgrounds/README.playground/Contents.swift | ./Scripts/markdown.swift
77
*/
88

99
enum TextBlock {
@@ -13,20 +13,23 @@ enum TextBlock {
1313
var block = TextBlock.unknown
1414

1515
while let line = readLine() {
16-
if line.hasPrefix("/*") {
17-
if block == .code {
18-
print("```")
19-
}
16+
switch block {
17+
case .unknown where line.isEmpty:
18+
break
19+
case .unknown where line.hasPrefix("/*"):
2020
block = .comment
21-
} else if line.hasSuffix("*/") {
22-
print("```swift")
21+
case .unknown:
2322
block = .code
24-
} else if block == .comment {
25-
print(line.drop(while: \.isWhitespace))
26-
} else {
23+
print("```swift")
2724
print(line)
25+
case .code where line.hasPrefix("/*"):
26+
block = .comment
27+
print("```")
28+
case .code:
29+
print(line)
30+
case .comment where line.hasSuffix("*/"):
31+
block = .unknown
32+
case .comment:
33+
print(line.drop(while: \.isWhitespace))
2834
}
2935
}
30-
if block == .code {
31-
print("```")
32-
}

0 commit comments

Comments
 (0)