summaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/blog/md/CodeBlockParser.kt
blob: 0c894fe66506ae90e011146f7d48265a3d69e7e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package moe.nea.blog.md

object CodeBlockParser : BlockParser {
    override fun detect(line: String): Boolean {
        return line.startsWith("```")
    }

    override fun parse(parser: MarkdownParser): MarkdownBlock {
        val language = parser.consumeLine()!!.removePrefix("```")
        val lines = mutableListOf<String>()
        while (true) {
            val line = parser.consumeLine() ?: error("Unfinished code block")
            if (line == "```")
                break
            lines.add(line)
        }
        return CodeBlock(language, lines)
    }

    override val prio: Int
        get() = 10

}