Add tasklist markdown extension
This commit is contained in:
parent
29e445ff41
commit
24ac5cf4fc
@ -42,6 +42,11 @@
|
||||
<artifactId>flexmark</artifactId>
|
||||
<version>0.62.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vladsch.flexmark</groupId>
|
||||
<artifactId>flexmark-ext-gfm-tasklist</artifactId>
|
||||
<version>0.62.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
|
||||
@ -11,6 +11,8 @@ object HtmlSanitizer {
|
||||
.allowAttributes("class").onElements("code")
|
||||
.allowUrlProtocols("http", "https")
|
||||
.allowAttributes("href").onElements("a")
|
||||
.allowElements("input")
|
||||
.allowAttributes("type", "checked", "disabled", "readonly").onElements("input")
|
||||
.requireRelNofollowOnLinks()
|
||||
.toFactory()!!
|
||||
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
package be.simplenotes.domain.usecases.markdown
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.Try
|
||||
import arrow.core.extensions.fx
|
||||
import arrow.core.left
|
||||
import arrow.core.right
|
||||
import be.simplenotes.domain.model.NoteMetadata
|
||||
import be.simplenotes.domain.validation.NoteValidations
|
||||
import com.auth0.jwt.JWT
|
||||
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension
|
||||
import com.vladsch.flexmark.html.HtmlRenderer
|
||||
import com.vladsch.flexmark.parser.Parser
|
||||
import com.vladsch.flexmark.util.data.MutableDataSet
|
||||
import io.konform.validation.ValidationErrors
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import org.yaml.snakeyaml.parser.ParserException
|
||||
import org.yaml.snakeyaml.scanner.ScannerException
|
||||
|
||||
|
||||
sealed class MarkdownParsingError
|
||||
object MissingMeta : MarkdownParsingError()
|
||||
object InvalidMeta : MarkdownParsingError()
|
||||
@ -60,8 +61,16 @@ internal class MarkdownConverterImpl : MarkdownConverter {
|
||||
return NoteMetadata(title, tags).right()
|
||||
}
|
||||
|
||||
private val parser = Parser.builder().build()
|
||||
private val renderer = HtmlRenderer.builder().build()
|
||||
private val parser: Parser
|
||||
private val renderer: HtmlRenderer
|
||||
|
||||
init {
|
||||
val options = MutableDataSet()
|
||||
options.set(Parser.EXTENSIONS, listOf(TaskListExtension.create()))
|
||||
parser = Parser.builder(options).build()
|
||||
renderer = HtmlRenderer.builder(options).build()
|
||||
}
|
||||
|
||||
private fun renderMarkdown(markdown: String) = parser.parse(markdown).run(renderer::render)
|
||||
|
||||
override fun renderDocument(input: String) = Either.fx<MarkdownParsingError, Document> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user