From 377d8c6deb09b0bf1992e5a3f8d921d38bc1cc9b Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Fri, 26 Jun 2020 18:43:35 +0300 Subject: [PATCH] Sample app another smple --- app-sample/samples.json | 12 +++++ .../app/samples/basics/SimpleWalkthrough.kt | 47 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 app-sample/src/main/java/io/noties/markwon/app/samples/basics/SimpleWalkthrough.kt diff --git a/app-sample/samples.json b/app-sample/samples.json index a3e1d5b2..aa01906b 100644 --- a/app-sample/samples.json +++ b/app-sample/samples.json @@ -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", "id": "202006178152255", diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/basics/SimpleWalkthrough.kt b/app-sample/src/main/java/io/noties/markwon/app/samples/basics/SimpleWalkthrough.kt new file mode 100644 index 00000000..7f9b1a6b --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/basics/SimpleWalkthrough.kt @@ -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) + } +} \ No newline at end of file