Sample app another smple

This commit is contained in:
Dimitry Ivanov 2020-06-26 18:43:35 +03:00
parent dc139319a0
commit 377d8c6deb
2 changed files with 59 additions and 0 deletions

View File

@ -1,4 +1,16 @@
[ [
{
"javaClassName": "io.noties.markwon.app.samples.basics.SimpleWalkthrough",
"id": "202006178153426",
"title": "Simple with walk-through",
"description": "Walk-through for simple use case",
"artifacts": [
"CORE"
],
"tags": [
"basics"
]
},
{ {
"javaClassName": "io.noties.markwon.app.samples.basics.Simple", "javaClassName": "io.noties.markwon.app.samples.basics.Simple",
"id": "202006178152255", "id": "202006178152255",

View File

@ -0,0 +1,47 @@
package io.noties.markwon.app.samples.basics
import android.text.Spanned
import io.noties.markwon.Markwon
import io.noties.markwon.app.sample.Tags
import io.noties.markwon.app.sample.ui.MarkwonTextViewSample
import io.noties.markwon.core.CorePlugin
import io.noties.markwon.sample.annotations.MarkwonArtifact
import io.noties.markwon.sample.annotations.MarkwonSampleInfo
import org.commonmark.node.Node
@MarkwonSampleInfo(
id = "202006178153426",
title = "Simple with walk-through",
description = "Walk-through for simple use case",
artifacts = [MarkwonArtifact.CORE],
tags = [Tags.basics]
)
class SimpleWalkthrough : MarkwonTextViewSample() {
override fun render() {
val md: String = """
# Hello!
> a quote
```
code block
```
""".trimIndent()
// create markwon instance via builder method
val markwon: Markwon = Markwon.builder(context)
// add required plugins
// NB, there is no need to add CorePlugin as it is added automatically
.usePlugin(CorePlugin.create())
.build()
// parse markdown into commonmark representation
val node: Node = markwon.parse(md)
// render commonmark node
val markdown: Spanned = markwon.render(node)
// apply it to a TextView
markwon.setParsedMarkdown(textView, markdown)
}
}