summaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/blog/md/ParagraphParser.kt
blob: 5e51786011729998361af560893cd4560ff3138a (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 == 1) {
                break
            }
            text += " $trimmedLine"
        }
        return Paragraph(parser.parseInlineText(text))
    }

    override val prio: Int
        get() = -10

}