diff --git a/app-sample/samples.json b/app-sample/samples.json index d7cd5f02..b2acd2a7 100644 --- a/app-sample/samples.json +++ b/app-sample/samples.json @@ -1,4 +1,28 @@ [ + { + "javaClassName": "io.noties.markwon.app.samples.HeadingColorSample", + "id": "20201203224611", + "title": "Color of heading", + "description": "", + "artifacts": [ + "CORE" + ], + "tags": [ + "rendering" + ] + }, + { + "javaClassName": "io.noties.markwon.app.samples.OrderedListNumbersSample", + "id": "20201203221806", + "title": "Ordered list numbers", + "description": "", + "artifacts": [ + "CORE" + ], + "tags": [ + "rendering" + ] + }, { "javaClassName": "io.noties.markwon.app.samples.ExcludeFromParsingSample", "id": "20201111221945", diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/HeadingColorSample.java b/app-sample/src/main/java/io/noties/markwon/app/samples/HeadingColorSample.java new file mode 100644 index 00000000..cda54353 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/HeadingColorSample.java @@ -0,0 +1,58 @@ +package io.noties.markwon.app.samples; + +import android.graphics.Color; +import android.text.style.ForegroundColorSpan; + +import androidx.annotation.NonNull; + +import org.commonmark.node.Heading; + +import io.noties.markwon.AbstractMarkwonPlugin; +import io.noties.markwon.Markwon; +import io.noties.markwon.MarkwonSpansFactory; +import io.noties.markwon.app.sample.Tags; +import io.noties.markwon.app.sample.ui.MarkwonTextViewSample; +import io.noties.markwon.core.CoreProps; +import io.noties.markwon.sample.annotations.MarkwonArtifact; +import io.noties.markwon.sample.annotations.MarkwonSampleInfo; + +@MarkwonSampleInfo( + id = "20201203224611", + title = "Color of heading", + artifacts = MarkwonArtifact.CORE, + tags = Tags.rendering +) +public class HeadingColorSample extends MarkwonTextViewSample { + @Override + public void render() { + + final String md = "" + + "# Heading 1\n" + + "## Heading 2\n" + + "### Heading 3\n" + + "#### Heading 4"; + + final Markwon markwon = Markwon.builder(context) + .usePlugin(new AbstractMarkwonPlugin() { + @Override + public void configureSpansFactory(@NonNull MarkwonSpansFactory.Builder builder) { + builder.appendFactory(Heading.class, (configuration, props) -> { + // here you can also inspect heading level + final int level = CoreProps.HEADING_LEVEL.require(props); + final int color; + if (level == 1) { + color = Color.RED; + } else if (level == 2) { + color = Color.GREEN; + } else { + color = Color.BLUE; + } + return new ForegroundColorSpan(color); + }); + } + }) + .build(); + + markwon.setMarkdown(textView, md); + } +} diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/OrderedListNumbersSample.java b/app-sample/src/main/java/io/noties/markwon/app/samples/OrderedListNumbersSample.java new file mode 100644 index 00000000..9f028839 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/OrderedListNumbersSample.java @@ -0,0 +1,48 @@ +package io.noties.markwon.app.samples; + +import io.noties.markwon.Markwon; +import io.noties.markwon.app.sample.Tags; +import io.noties.markwon.app.sample.ui.MarkwonTextViewSample; +import io.noties.markwon.sample.annotations.MarkwonArtifact; +import io.noties.markwon.sample.annotations.MarkwonSampleInfo; + +@MarkwonSampleInfo( + id = "20201203221806", + title = "Ordered list numbers", + artifacts = MarkwonArtifact.CORE, + tags = Tags.rendering +) +public class OrderedListNumbersSample extends MarkwonTextViewSample { + @Override + public void render() { + final String md = "# Ordered lists\n\n" + + "1. hello there\n" + + "1. hello there and much much more, this text just goes and goes, and should it stop, we' know it\n" + + "1. okay, np\n" + + "1. hello there\n" + + "1. hello there and much much more, this text just goes and goes, and should it stop, we' know it\n" + + "1. okay, np\n" + + "1. hello there\n" + + "1. hello there and much much more, this text just goes and goes, and should it stop, we' know it\n" + + "1. okay, np\n" + + "1. hello there\n" + + "1. hello there and much much more, this text just goes and goes, and should it stop, we' know it\n" + + "1. okay, np\n" + + "1. hello there\n" + + "1. hello there and much much more, this text just goes and goes, and should it stop, we' know it\n" + + "1. okay, np\n" + + "1. hello there\n" + + "1. hello there and much much more, this text just goes and goes, and should it stop, we' know it\n" + + "1. okay, np\n" + + "1. hello there\n" + + "1. hello there and much much more, this text just goes and goes, and should it stop, we' know it\n" + + "1. okay, np\n" + + "1. hello there\n" + + "1. hello there and much much more, this text just goes and goes, and should it stop, we' know it\n" + + "1. okay, np\n" + + ""; + + final Markwon markwon = Markwon.create(context); + markwon.setMarkdown(textView, md); + } +}