JetBrains / markdown

Markdown parser written in kotlin
Apache License 2.0
682 stars 75 forks source link

Markdown parsing fails on Kotlin/JS #78

Closed sureshg closed 3 years ago

sureshg commented 3 years ago

The basic example given in the project page is fails to run on Kotlin/JS application with Invalid regular expression error.

val src = "Some *markdown*"
val flavour = GFMFlavourDescriptor()
val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(src)
val html = HtmlGenerator(src, parsedTree, flavour).generateHtml()
log("Markdown : $html")

Version Used:

 kotlin("js") version "1.5.0-RC"
 implementation("org.jetbrains:markdown:0.2.2")
kotlin_kotlin.js?215f:19299 SyntaxError: Invalid regular expression: /^ {0,3}(\-+|=+) *$/: Invalid escape
    at new RegExp (<anonymous>)
    at Regex (webpack-internal:///./kotlin/kotlin_kotlin.js:18373:26)
    at Regex_init_$Init$_0 (webpack-internal:///./kotlin/kotlin_kotlin.js:18294:11)
    at Regex_init_$Create$_0 (webpack-internal:///./kotlin/kotlin_kotlin.js:18298:12)
    at new Companion_126 (webpack-internal:///./kotlin/kotlin_org_jetbrains_markdown.js:9168:21)
    at Companion_getInstance_125 (webpack-internal:///./kotlin/kotlin_org_jetbrains_markdown.js:9181:7)
    at new SetextHeaderProvider (webpack-internal:///./kotlin/kotlin_org_jetbrains_markdown.js:9185:5)
    at GFMMarkerProcessor.CommonMarkMarkerProcessor [as constructor] (webpack-internal:///./kotlin/kotlin_org_jetbrains_markdown.js:1234:122)
    at new GFMMarkerProcessor (webpack-internal:///./kotlin/kotlin_org_jetbrains_markdown.js:1875:31)
    at Factory_1.createMarkerProcessor_1 (webpack-internal:///./kotlin/kotlin_org_jetbrains_markdown.js:1861:12)
ajalt commented 3 years ago

I think this is caused by Kotlin 1.5. Updating this library to 1.5 reproduces the issue.

ajalt commented 3 years ago

I reported this as KT-46694, although it should be possible to workaround this issue in the meantime.

NebuPookins commented 3 years ago

What's the workaround? To just downgrade to 1.4?

ajalt commented 3 years ago

The workaround from this library would be to adjust the regex to avoid the bug. For users of this library right now, I think you're correct that the only solution is to downgrade to Kotlin 1.4.