diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/blog/md/CodeBlockParser.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/blog/md/CodeBlockParser.kt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/blog/md/CodeBlockParser.kt b/src/main/kotlin/moe/nea/blog/md/CodeBlockParser.kt new file mode 100644 index 0000000..0c894fe --- /dev/null +++ b/src/main/kotlin/moe/nea/blog/md/CodeBlockParser.kt @@ -0,0 +1,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 + +}
\ No newline at end of file |