summaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/blog/md/ParagraphParser.kt
blob: 328c49b4c7b041a5e047f6b0cc54f682986d2b4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package moe.nea.blog.md

object ParagraphParser : BlockParser {
    override fun detect(line: String): Boolean {
        return true
    }

    override fun parse(parser: MarkdownParser): MarkdownBlock {
        var text = ""
        var emptyLineCount = 0
        while (true) {
            val line = parser.peekLine() ?: break
            if (parser.findParserFor(line) != null) break
            val trimmedLine = parser.consumeLine()!!.trim()
            if (trimmedLine == "") {
                emptyLineCount++
            } else {
                emptyLineCount = 0
            }
            if (emptyLineCount == 2) {
                break
            }
            text += " $trimmedLine"
        }
        return Paragraph(parser.parseInlineText(text))
    }

    override val prio: Int
        get() = -10

}