sample, add thematic break bottom margin sample
This commit is contained in:
parent
06413aaf36
commit
854fa744c7
@ -1,4 +1,16 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"javaClassName": "io.noties.markwon.app.samples.ThematicBreakBottomMarginSample",
|
||||||
|
"id": "20200813154415",
|
||||||
|
"title": "Thematic break bottom margin",
|
||||||
|
"description": "Do not add a new line after thematic break (with the `BlockHandler`)",
|
||||||
|
"artifacts": [
|
||||||
|
"CORE"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"rendering"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"javaClassName": "io.noties.markwon.app.samples.RedditSpoilerSample",
|
"javaClassName": "io.noties.markwon.app.samples.RedditSpoilerSample",
|
||||||
"id": "20200813145316",
|
"id": "20200813145316",
|
||||||
@ -822,12 +834,13 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"javaClassName": "io.noties.markwon.app.samples.GithubUserIssueOnTextAddedSample",
|
"javaClassName": "io.noties.markwon.app.samples.GithubUserIssueInlineParsingSample",
|
||||||
"id": "20200629162024",
|
"id": "20200629162024",
|
||||||
"title": "User mention and issue (via text)",
|
"title": "User mention and issue (via text)",
|
||||||
"description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`",
|
"description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`",
|
||||||
"artifacts": [
|
"artifacts": [
|
||||||
"CORE"
|
"CORE",
|
||||||
|
"INLINE_PARSER"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"parsing",
|
"parsing",
|
||||||
@ -836,13 +849,12 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"javaClassName": "io.noties.markwon.app.samples.GithubUserIssueInlineParsingSample",
|
"javaClassName": "io.noties.markwon.app.samples.GithubUserIssueOnTextAddedSample",
|
||||||
"id": "20200629162024",
|
"id": "20200629162024",
|
||||||
"title": "User mention and issue (via text)",
|
"title": "User mention and issue (via text)",
|
||||||
"description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`",
|
"description": "Github-like user mention and issue rendering via `CorePlugin.OnTextAddedListener`",
|
||||||
"artifacts": [
|
"artifacts": [
|
||||||
"CORE",
|
"CORE"
|
||||||
"INLINE_PARSER"
|
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"parsing",
|
"parsing",
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
package io.noties.markwon.app.samples;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.commonmark.node.Node;
|
||||||
|
import org.commonmark.node.ThematicBreak;
|
||||||
|
|
||||||
|
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||||
|
import io.noties.markwon.BlockHandlerDef;
|
||||||
|
import io.noties.markwon.Markwon;
|
||||||
|
import io.noties.markwon.MarkwonVisitor;
|
||||||
|
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 = "20200813154415",
|
||||||
|
title = "Thematic break bottom margin",
|
||||||
|
description = "Do not add a new line after thematic break (with the `BlockHandler`)",
|
||||||
|
artifacts = MarkwonArtifact.CORE,
|
||||||
|
tags = Tags.rendering
|
||||||
|
)
|
||||||
|
public class ThematicBreakBottomMarginSample extends MarkwonTextViewSample {
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
final String md = "" +
|
||||||
|
"# Thematic break and margin\n\n" +
|
||||||
|
"So, what if....\n\n" +
|
||||||
|
"---\n\n" +
|
||||||
|
"And **now**";
|
||||||
|
|
||||||
|
final Markwon markwon = Markwon.builder(context)
|
||||||
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
|
@Override
|
||||||
|
public void configureVisitor(@NonNull MarkwonVisitor.Builder builder) {
|
||||||
|
builder.blockHandler(new BlockHandlerDef() {
|
||||||
|
@Override
|
||||||
|
public void blockStart(@NonNull MarkwonVisitor visitor, @NonNull Node node) {
|
||||||
|
// also can control block start
|
||||||
|
super.blockStart(visitor, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void blockEnd(@NonNull MarkwonVisitor visitor, @NonNull Node node) {
|
||||||
|
if (visitor.hasNext(node)) {
|
||||||
|
visitor.ensureNewLine();
|
||||||
|
|
||||||
|
// thematic break won't have a new line
|
||||||
|
// similarly you can control other blocks
|
||||||
|
if (!(node instanceof ThematicBreak)) {
|
||||||
|
visitor.forceNewLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
markwon.setMarkdown(textView, md);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user