summaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/blog/md
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/blog/md')
-rw-r--r--src/main/kotlin/moe/nea/blog/md/BlockQuote.kt14
-rw-r--r--src/main/kotlin/moe/nea/blog/md/BlockQuoteParser.kt33
-rw-r--r--src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt1
3 files changed, 48 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/blog/md/BlockQuote.kt b/src/main/kotlin/moe/nea/blog/md/BlockQuote.kt
new file mode 100644
index 0000000..ba3824f
--- /dev/null
+++ b/src/main/kotlin/moe/nea/blog/md/BlockQuote.kt
@@ -0,0 +1,14 @@
+package moe.nea.blog.md
+
+import moe.nea.blog.util.indent
+import java.io.PrintStream
+
+class BlockQuote(val inner: MarkdownBlock) : MarkdownBlock {
+ override fun debugFormat(indent: Int, printStream: PrintStream) {
+ printStream.indent(indent)
+ printStream.println("<quote>")
+ inner.debugFormat(indent + 2, printStream)
+ printStream.indent(indent)
+ printStream.println("</quote>")
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/blog/md/BlockQuoteParser.kt b/src/main/kotlin/moe/nea/blog/md/BlockQuoteParser.kt
new file mode 100644
index 0000000..c37e215
--- /dev/null
+++ b/src/main/kotlin/moe/nea/blog/md/BlockQuoteParser.kt
@@ -0,0 +1,33 @@
+package moe.nea.blog.md
+
+object BlockQuoteParser : BlockParser {
+ override fun detect(line: String): Boolean {
+ return line.startsWith("> ")
+ }
+
+ override fun parse(parser: MarkdownParser): MarkdownBlock {
+ parser.pushPreProcessor(
+ LinePreProcessor.whileIgnoringFirst(
+ parser.getIndent()
+ ) { _, line ->
+ if (!line.startsWith("> ") && line != ">") {
+ null
+ } else {
+ " " + line.substring(2)
+ }
+ }
+ )
+ parser.pushIndent(2)
+ val blocks = mutableListOf<MarkdownBlock>()
+ while (true) {
+ val child = parser.readChildBlock() ?: break
+ blocks.add(child)
+ }
+ parser.popPreProcessor()
+ parser.popIndent()
+ return BlockQuote(parser.mergeBlocks(blocks))
+ }
+
+ override val prio: Int
+ get() = 10
+} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt b/src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt
index 5ee984f..11aff14 100644
--- a/src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt
+++ b/src/main/kotlin/moe/nea/blog/md/MarkdownParser.kt
@@ -170,6 +170,7 @@ class MarkdownParser(source: String) {
blockParsers.add(CodeBlockParser)
blockParsers.add(HeaderParser)
blockParsers.add(ListParser)
+ blockParsers.add(BlockQuoteParser)
inlineParsers.add(ItalicsParser)
inlineParsers.add(LinkParser)
inlineParsers.add(ImageParser)