Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Make MarkdownParser instantiatable
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-makes-code committed Feb 14, 2023
1 parent b58d374 commit 819024c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/main/kotlin/dev/proxyfox/markt/Parser.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dev.proxyfox.markt

public object MarkdownParser {
private const val ESCAPE = '\\'

public class MarkdownParser {
public val rules: ArrayList<MarkdownRule> = arrayListOf()

public fun parse(content: String): RootNode {
Expand Down Expand Up @@ -75,4 +73,13 @@ public object MarkdownParser {
public inline operator fun <reified T : MarkdownRule> plusAssign(rule: T): Unit = +rule

public operator fun invoke(init: MarkdownParser.() -> Unit): Unit = init()

public companion object {
private const val ESCAPE = '\\'
public val globalInstance: MarkdownParser = MarkdownParser()

init {
globalInstance.addDefaultRules()
}
}
}
3 changes: 1 addition & 2 deletions src/test/kotlin/dev/proxyfox/markt/test/MarKtTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ val stringsToTest = arrayListOf(
class MarKtTests {
@Test
fun testMarkdown() {
MarkdownParser.addDefaultRules()
for (test in stringsToTest) {
println("Input: ${test.first}\n")
println("Expected\n${test.second.toTreeString()}")
val parsed = MarkdownParser.parse(test.first)
val parsed = MarkdownParser.globalInstance.parse(test.first)
println("Parsed:\n${parsed.toTreeString()}")
assert(parsed == test.second)
}
Expand Down

0 comments on commit 819024c

Please sign in to comment.