From eca93dd27cc2643661dd2840af5d9cb40df7c146 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Mon, 24 Jun 2019 15:08:43 +0300 Subject: [PATCH] Add simple-ext documentation --- docs/.vuepress/.artifacts.js | 2 +- docs/.vuepress/config.js | 1 + docs/docs/v4/simple-ext/README.md | 62 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 docs/docs/v4/simple-ext/README.md diff --git a/docs/.vuepress/.artifacts.js b/docs/.vuepress/.artifacts.js index a0f2a8de..62c52ab8 100644 --- a/docs/.vuepress/.artifacts.js +++ b/docs/.vuepress/.artifacts.js @@ -1,4 +1,4 @@ // this is a generated file, do not modify. To update it run 'collectArtifacts.js' script -const artifacts = [{"id":"core","name":"Core","group":"io.noties.markwon","description":"Core Markwon artifact that includes basic markdown parsing and rendering"},{"id":"ext-latex","name":"LaTeX","group":"io.noties.markwon","description":"Extension to add LaTeX formulas to Markwon markdown"},{"id":"ext-strikethrough","name":"Strikethrough","group":"io.noties.markwon","description":"Extension to add strikethrough markup to Markwon markdown"},{"id":"ext-tables","name":"Tables","group":"io.noties.markwon","description":"Extension to add tables markup (GFM) to Markwon markdown"},{"id":"ext-tasklist","name":"Task List","group":"io.noties.markwon","description":"Extension to add task lists (GFM) to Markwon markdown"},{"id":"html","name":"HTML","group":"io.noties.markwon","description":"Provides HTML parsing functionality"},{"id":"image","name":"Image","group":"io.noties.markwon","description":"Markwon image loading module (with optional GIF and SVG support)"},{"id":"image-glide","name":"Image Glide","group":"io.noties.markwon","description":"Markwon image loading module (based on Glide library)"},{"id":"image-picasso","name":"Image Picasso","group":"io.noties.markwon","description":"Markwon image loading module (based on Picasso library)"},{"id":"linkify","name":"Linkify","group":"io.noties.markwon","description":"Markwon plugin to linkify text (based on Android Linkify)"},{"id":"recycler","name":"Recycler","group":"io.noties.markwon","description":"Provides RecyclerView.Adapter to display Markwon markdown"},{"id":"recycler-table","name":"Recycler Table","group":"io.noties.markwon","description":"Provides MarkwonAdapter.Entry to render TableBlocks inside Android-native TableLayout widget"},{"id":"syntax-highlight","name":"Syntax Highlight","group":"io.noties.markwon","description":"Add syntax highlight to Markwon markdown via Prism4j library"}]; +const artifacts = [{"id":"core","name":"Core","group":"io.noties.markwon","description":"Core Markwon artifact that includes basic markdown parsing and rendering"},{"id":"ext-latex","name":"LaTeX","group":"io.noties.markwon","description":"Extension to add LaTeX formulas to Markwon markdown"},{"id":"ext-strikethrough","name":"Strikethrough","group":"io.noties.markwon","description":"Extension to add strikethrough markup to Markwon markdown"},{"id":"ext-tables","name":"Tables","group":"io.noties.markwon","description":"Extension to add tables markup (GFM) to Markwon markdown"},{"id":"ext-tasklist","name":"Task List","group":"io.noties.markwon","description":"Extension to add task lists (GFM) to Markwon markdown"},{"id":"html","name":"HTML","group":"io.noties.markwon","description":"Provides HTML parsing functionality"},{"id":"image","name":"Image","group":"io.noties.markwon","description":"Markwon image loading module (with optional GIF and SVG support)"},{"id":"image-glide","name":"Image Glide","group":"io.noties.markwon","description":"Markwon image loading module (based on Glide library)"},{"id":"image-picasso","name":"Image Picasso","group":"io.noties.markwon","description":"Markwon image loading module (based on Picasso library)"},{"id":"linkify","name":"Linkify","group":"io.noties.markwon","description":"Markwon plugin to linkify text (based on Android Linkify)"},{"id":"recycler","name":"Recycler","group":"io.noties.markwon","description":"Provides RecyclerView.Adapter to display Markwon markdown"},{"id":"recycler-table","name":"Recycler Table","group":"io.noties.markwon","description":"Provides MarkwonAdapter.Entry to render TableBlocks inside Android-native TableLayout widget"},{"id":"simple-ext","name":"Simple Extension","group":"io.noties.markwon","description":"Custom extension based on simple delimiter usage"},{"id":"syntax-highlight","name":"Syntax Highlight","group":"io.noties.markwon","description":"Add syntax highlight to Markwon markdown via Prism4j library"}]; export { artifacts }; diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 27a4dd6b..fe306167 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -65,6 +65,7 @@ module.exports = { '/docs/v4/linkify/', '/docs/v4/recycler/', '/docs/v4/recycler-table/', + '/docs/v4/simple-ext/', '/docs/v4/syntax-highlight/', '/docs/v4/recipes.md', '/docs/v4/migration-3-4.md' diff --git a/docs/docs/v4/simple-ext/README.md b/docs/docs/v4/simple-ext/README.md new file mode 100644 index 00000000..c16fc085 --- /dev/null +++ b/docs/docs/v4/simple-ext/README.md @@ -0,0 +1,62 @@ +# Simple Extension + + + +`SimpleExtPlugin` allows creating simple _delimited_ extensions, for example: + +```md ++this is text surrounded by `+`+ +``` + +```java +final Markwon markwon = Markwon.builder(this) + .usePlugin(SimpleExtPlugin.create(plugin -> plugin + // +sometext+ + .addExtension(1, '+', new SpanFactory() { + @Override + public Object getSpans(@NonNull MarkwonConfiguration configuration, @NonNull RenderProps props) { + return new EmphasisSpan(); + } + }) + .build(); +``` + +or + +```java +final Markwon markwon = Markwon.builder(this) + .usePlugin(SimpleExtPlugin.create()) + .usePlugin(new AbstractMarkwonPlugin() { + @Override + public void configure(@NonNull Registry registry) { + registry.require(SimpleExtPlugin.class, new Action() { + @Override + public void apply(@NonNull SimpleExtPlugin plugin) { + plugin.addExtension(1, '+', new SpanFactory() { + @Override + public Object getSpans(@NonNull MarkwonConfiguration configuration, @NonNull RenderProps props) { + return new EmphasisSpan(); + } + }) + } + }); + } + }) + .build(); +``` + +If opening and closing characters are different another method can be used: + +```java +plugin.addExtension( + /*length*/2, + /*openingCharacter*/'@', + /*closingCharacter*/'$', + /*spanFactory*/(configuration, props) -> new ForegroundColorSpan(Color.RED)))) +``` + +This extension will be applied to a text like this: + +```md +@@we are inside different delimiter characters$$ +```