summaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/blog
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-03-24 16:15:13 +0100
committerLinnea Gräf <nea@nea.moe>2024-03-24 16:15:13 +0100
commit340fc50af3a33f5d3f2fc1928d6ce34baae0bd4e (patch)
tree0078cea8857364e32e4fcced9ad733000208687d /src/main/kotlin/moe/nea/blog
parent238dabfe06fade0cd9a2b0fc286bddc6a48151f6 (diff)
downloadblog-infra-340fc50af3a33f5d3f2fc1928d6ce34baae0bd4e.tar.gz
blog-infra-340fc50af3a33f5d3f2fc1928d6ce34baae0bd4e.tar.bz2
blog-infra-340fc50af3a33f5d3f2fc1928d6ce34baae0bd4e.zip
Add freestanding star test
Diffstat (limited to 'src/main/kotlin/moe/nea/blog')
-rw-r--r--src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt b/src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt
index 19a4e99..40c4c30 100644
--- a/src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt
+++ b/src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt
@@ -70,17 +70,21 @@ class MarkdownParser(source: String) {
}
fun parseInlineTextOnce(lookback: MarkdownFormat, text: String): Pair<MarkdownFormat, String> {
+ require(text.isNotEmpty()) // TODO handle empty string
val parser = inlineParsers.find { it.detect(lookback, text) }
- if (parser != null)
+ if (parser != null) {
return parser.parse(this, text)
- require(!text.isEmpty()) // TODO handle empty string
- if (text[0] == ' ')
+ }
+ if (text[0] == ' ') {
return Pair(Whitespace(), text.substring(1))
+ }
val nextSpecial = text.indexOfFirst { it in inlineParsers.flatMap { it.specialSyntax } || it == ' ' }
- if (nextSpecial == 0)
+ if (nextSpecial == 0) {
return Pair(Word(text.substring(0, 1)), text.substring(1))
- if (nextSpecial == -1)
+ }
+ if (nextSpecial == -1) {
return Pair(Word(text), "")
+ }
return Pair(Word(text.substring(0, nextSpecial)), text.substring(nextSpecial))
}