JetBrains / markdown

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

Add support for cancellation of the parsing process #141

Closed FirstTimeInForever closed 9 months ago

FirstTimeInForever commented 9 months ago

Sometimes it is needed to cancel the currently running parsing process (e.g. if the input was updated and the parsing result would be immediately outdated). Typing in some editor can be considered an example of such a case.

To achieve this, we can provide an instance of CancellationToken to the parser:

fun interface CancellationToken {
    fun checkCancelled()
}

The parser can then call checkCancelled in relevant places (loops/ast construction/html generation/...) to abort its execution if needed.