diff --git a/app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java b/app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java index 9bcb8e0f..15583b65 100644 --- a/app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java +++ b/app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java @@ -10,6 +10,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.Future; import javax.inject.Inject; @@ -18,6 +19,7 @@ import io.noties.debug.Debug; import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; +import io.noties.markwon.PrecomputedTextSetterCompat; import io.noties.markwon.app.gif.GifAwarePlugin; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.ext.tables.TablePlugin; @@ -73,6 +75,11 @@ public class MarkdownRenderer { cancel(); +final Markwon markwon = Markwon.builder(context) + .usePlugin(/**/) + .textSetter(PrecomputedTextSetterCompat.create(Executors.newCachedThreadPool())) + .build(); + task = service.submit(new Runnable() { @Override diff --git a/docs/.vuepress/components/LegacyWarning.vue b/docs/.vuepress/components/LegacyWarning.vue index b84e9cea..5f1d585f 100644 --- a/docs/.vuepress/components/LegacyWarning.vue +++ b/docs/.vuepress/components/LegacyWarning.vue @@ -1,7 +1,7 @@ diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index de897e67..cd58b64c 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -16,9 +16,17 @@ module.exports = { { text: 'API Version', items: [ - { text: 'Current (4.x.x)', link: '/' }, - { text: 'Legacy (3.x.x)', link: '/docs/v3/install.md' }, - { text: 'Legacy (2.x.x)', link: '/docs/v2/' } + { + text: 'Latest', items: [ + { text: '4.x.x', link: '/' }, + ] + }, + { + text: 'Legacy', items: [ + { text: '3.x.x', link: '/docs/v3/install.md' }, + { text: '2.x.x', link: '/docs/v2/' } + ] + } ] }, { text: 'Changelog', link: 'https://github.com/noties/Markwon/blob/master/CHANGELOG.md' }, @@ -83,7 +91,8 @@ module.exports = { '/docs/v4/core/spans-factory.md', '/docs/v4/core/core-plugin.md', '/docs/v4/core/movement-method-plugin.md', - '/docs/v4/core/render-props.md' + '/docs/v4/core/render-props.md', + '/docs/v4/core/text-setter.md' ] }, '/docs/v4/ext-latex/', diff --git a/docs/docs/v3/core/configuration.md b/docs/docs/v3/core/configuration.md index 245b3310..db5d3f96 100644 --- a/docs/docs/v3/core/configuration.md +++ b/docs/docs/v3/core/configuration.md @@ -1,5 +1,7 @@ # Configuration + + `MarkwonConfiguration` class holds common Markwon functionality. These are _configurable_ properties: * `SyntaxHighlight` diff --git a/docs/docs/v3/core/core-plugin.md b/docs/docs/v3/core/core-plugin.md index 3a63c2c5..41c92a45 100644 --- a/docs/docs/v3/core/core-plugin.md +++ b/docs/docs/v3/core/core-plugin.md @@ -1,5 +1,7 @@ # Core plugin + + Since with introduction of _plugins_, Markwon **core** functionality was moved to a dedicated plugin. diff --git a/docs/docs/v3/core/getting-started.md b/docs/docs/v3/core/getting-started.md index 652cfb7c..60dc0451 100644 --- a/docs/docs/v3/core/getting-started.md +++ b/docs/docs/v3/core/getting-started.md @@ -1,5 +1,7 @@ # Getting started + + :::tip Installation Please follow [installation](/docs/v3/install.md) instructions to learn how to add `Markwon` to your project diff --git a/docs/docs/v3/core/html-renderer.md b/docs/docs/v3/core/html-renderer.md index 17ef63e3..1b5e4761 100644 --- a/docs/docs/v3/core/html-renderer.md +++ b/docs/docs/v3/core/html-renderer.md @@ -1,5 +1,7 @@ # HTML Renderer + + Starting with `MarkwonHtmlRenderer` controls how HTML is rendered: diff --git a/docs/docs/v3/core/images.md b/docs/docs/v3/core/images.md index 4aa675e2..75361d86 100644 --- a/docs/docs/v3/core/images.md +++ b/docs/docs/v3/core/images.md @@ -1,5 +1,7 @@ # Images + + Starting with `Markwon` comes with `ImagesPlugin` which supports `http(s)`, `file` and `data` schemes and default media decoder (for simple images, no [SVG](/docs/v3/image/svg.md) or [GIF](/docs/v3/image/gif.md) which diff --git a/docs/docs/v3/core/movement-method-plugin.md b/docs/docs/v3/core/movement-method-plugin.md index 6bb50c87..86fe43d2 100644 --- a/docs/docs/v3/core/movement-method-plugin.md +++ b/docs/docs/v3/core/movement-method-plugin.md @@ -1,5 +1,7 @@ # Movement method plugin + + `MovementMethodPlugin` can be used to apply a `MovementMethod` to a TextView (important if you have links inside your markdown). By default `CorePlugin` will set a `LinkMovementMethod` on a TextView if one is missing. If you have diff --git a/docs/docs/v3/core/plugins.md b/docs/docs/v3/core/plugins.md index dd83ab76..62052c32 100644 --- a/docs/docs/v3/core/plugins.md +++ b/docs/docs/v3/core/plugins.md @@ -1,5 +1,7 @@ # Plugins + + Since `MarkwonPlugin` takes the key role in processing and rendering markdown. Even **core** functionaly is abstracted into a `CorePlugin`. So it's still possible to use `Markwon` with a completely diff --git a/docs/docs/v3/core/render-props.md b/docs/docs/v3/core/render-props.md index 9dd18004..fb75479d 100644 --- a/docs/docs/v3/core/render-props.md +++ b/docs/docs/v3/core/render-props.md @@ -1,5 +1,7 @@ # RenderProps + + `RenderProps` encapsulates passing arguments from a node visitor to a node renderer. Without hardcoding arguments into an API method calls. diff --git a/docs/docs/v3/core/spans-factory.md b/docs/docs/v3/core/spans-factory.md index 6044de9a..e6536dd0 100644 --- a/docs/docs/v3/core/spans-factory.md +++ b/docs/docs/v3/core/spans-factory.md @@ -1,5 +1,7 @@ # Spans Factory + + Starting with `MarkwonSpansFactory` controls what spans are displayed for markdown nodes. diff --git a/docs/docs/v3/core/theme.md b/docs/docs/v3/core/theme.md index 672babc6..1b7d524f 100644 --- a/docs/docs/v3/core/theme.md +++ b/docs/docs/v3/core/theme.md @@ -1,5 +1,7 @@ # Theme + + Here is the list of properties that can be configured via `MarkwonTheme.Builder` class. :::tip diff --git a/docs/docs/v3/core/visitor.md b/docs/docs/v3/core/visitor.md index f0cce0f2..ef0ffee6 100644 --- a/docs/docs/v3/core/visitor.md +++ b/docs/docs/v3/core/visitor.md @@ -1,5 +1,7 @@ # Visitor + + Starting with _visiting_ of parsed markdown nodes does not require creating own instance of commonmark-java `Visitor`, instead a composable/configurable `MarkwonVisitor` is used. diff --git a/docs/docs/v3/ext-latex/README.md b/docs/docs/v3/ext-latex/README.md index ea1256f0..a0f1b601 100644 --- a/docs/docs/v3/ext-latex/README.md +++ b/docs/docs/v3/ext-latex/README.md @@ -1,5 +1,7 @@ # LaTeX extension + + This is an extension that will help you display LaTeX formulas in your markdown. diff --git a/docs/docs/v3/ext-strikethrough/README.md b/docs/docs/v3/ext-strikethrough/README.md index 9bbfc0e5..ce0d9f4d 100644 --- a/docs/docs/v3/ext-strikethrough/README.md +++ b/docs/docs/v3/ext-strikethrough/README.md @@ -1,5 +1,7 @@ # Strikethrough extension + + This module adds `strikethrough` functionality to `Markwon` via `StrikethroughPlugin`: diff --git a/docs/docs/v3/ext-tables/README.md b/docs/docs/v3/ext-tables/README.md index 49282a05..dc0813b0 100644 --- a/docs/docs/v3/ext-tables/README.md +++ b/docs/docs/v3/ext-tables/README.md @@ -1,5 +1,7 @@ # Tables extension + + This extension adds support for GFM tables. diff --git a/docs/docs/v3/ext-tasklist/README.md b/docs/docs/v3/ext-tasklist/README.md index 3fb332f4..cda66aa5 100644 --- a/docs/docs/v3/ext-tasklist/README.md +++ b/docs/docs/v3/ext-tasklist/README.md @@ -1,5 +1,7 @@ # Task list extension + + Adds support for GFM (Github-flavored markdown) task-lists: diff --git a/docs/docs/v3/html/README.md b/docs/docs/v3/html/README.md index 12f66400..36e08abc 100644 --- a/docs/docs/v3/html/README.md +++ b/docs/docs/v3/html/README.md @@ -1,5 +1,7 @@ # HTML + + This artifact encapsulates HTML parsing from the core artifact and provides few predefined `TagHandlers` diff --git a/docs/docs/v3/image/gif.md b/docs/docs/v3/image/gif.md index 56ce081c..f3d3b5a6 100644 --- a/docs/docs/v3/image/gif.md +++ b/docs/docs/v3/image/gif.md @@ -1,5 +1,7 @@ # Image GIF + + Adds support for GIF images inside markdown. diff --git a/docs/docs/v3/image/okhttp.md b/docs/docs/v3/image/okhttp.md index 4a7c159d..fc61b1d9 100644 --- a/docs/docs/v3/image/okhttp.md +++ b/docs/docs/v3/image/okhttp.md @@ -1,5 +1,7 @@ # Image OkHttp + + Uses [okhttp library](https://github.com/square/okhttp) as the network transport fro images. Since diff --git a/docs/docs/v3/image/svg.md b/docs/docs/v3/image/svg.md index 538c524c..cf060251 100644 --- a/docs/docs/v3/image/svg.md +++ b/docs/docs/v3/image/svg.md @@ -1,5 +1,7 @@ # Image SVG + + Adds support for SVG images inside markdown. diff --git a/docs/docs/v3/install.md b/docs/docs/v3/install.md index 19c28cba..1d76b5c2 100644 --- a/docs/docs/v3/install.md +++ b/docs/docs/v3/install.md @@ -3,6 +3,8 @@ prev: false next: /docs/v3/core/getting-started.md --- + + # Installation ![stable](https://img.shields.io/maven-central/v/ru.noties.markwon/core.svg?label=stable) diff --git a/docs/docs/v3/migration-2-3.md b/docs/docs/v3/migration-2-3.md index aeb045c6..2fdcd884 100644 --- a/docs/docs/v3/migration-2-3.md +++ b/docs/docs/v3/migration-2-3.md @@ -1,5 +1,7 @@ # Migration 2.x.x -> 3.x.x + + * strikethrough moved to standalone module * tables moved to standalone module * core functionality of `AsyncDrawableLoader` moved to `core` module diff --git a/docs/docs/v3/recycler-table/README.md b/docs/docs/v3/recycler-table/README.md index e7287649..a377b041 100644 --- a/docs/docs/v3/recycler-table/README.md +++ b/docs/docs/v3/recycler-table/README.md @@ -1,5 +1,7 @@ # Recycler Table + + Artifact that provides [MarkwonAdapter.Entry](/docs/v3/recycler/) to render `TableBlock` inside diff --git a/docs/docs/v3/recycler/README.md b/docs/docs/v3/recycler/README.md index 73b05826..635fbcf4 100644 --- a/docs/docs/v3/recycler/README.md +++ b/docs/docs/v3/recycler/README.md @@ -1,5 +1,7 @@ # Recycler + + This artifact allows displaying markdown in a set of Android widgets diff --git a/docs/docs/v3/syntax-highlight/README.md b/docs/docs/v3/syntax-highlight/README.md index a5203cf6..cc47f6f5 100644 --- a/docs/docs/v3/syntax-highlight/README.md +++ b/docs/docs/v3/syntax-highlight/README.md @@ -1,5 +1,7 @@ # Syntax highlight + + This is a simple module to add **syntax highlight** functionality to your markdown rendered with `Markwon` library. It is based on [Prism4j](https://github.com/noties/Prism4j) so lead there to understand how to configure `Prism4j` instance. diff --git a/docs/docs/v4/core/text-setter.md b/docs/docs/v4/core/text-setter.md new file mode 100644 index 00000000..c69d0e58 --- /dev/null +++ b/docs/docs/v4/core/text-setter.md @@ -0,0 +1,40 @@ +# TextSetter + +Since it is possible to control how text is applied to a `TextView`. +This is done via `Markwon.TextSetter` interface. + +```java +final Markwon markwon = Markwon.builder(context) + .usePlugin(/**/) + .textSetter(PrecomputedTextSetterCompat.create(Executors.newCachedThreadPool())) + .build(); +``` + +```java +public interface TextSetter { + /** + * @param textView TextView + * @param markdown prepared markdown + * @param bufferType BufferType specified when building {@link Markwon} instance + * via {@link Builder#bufferType(TextView.BufferType)} + * @param onComplete action to run when set-text is finished (required to call in order + * to execute {@link MarkwonPlugin#afterSetText(TextView)}) + */ + void setText( + @NonNull TextView textView, + @NonNull Spanned markdown, + @NonNull TextView.BufferType bufferType, + @NonNull Runnable onComplete); +} +``` + +Primary target for this functionality is to use [PrecomputedText] and [PrecomputedTextCompat]. +`Markwon` comes with `PrecomputedTextSetterCompat` implementation. + +:::tip Note +Please note that `PrecomputedTextCompat` belongs to the `androidx.core:core` artifact. Make +sure that you have it in your project's dependencies (explicitly or implicitly) +::: + +[PrecomputedText]: https://developer.android.com/reference/android/text/PrecomputedText +[PrecomputedTextCompat]: https://developer.android.com/reference/androidx/core/text/PrecomputedTextCompat \ No newline at end of file diff --git a/markwon-core/src/main/java/io/noties/markwon/Markwon.java b/markwon-core/src/main/java/io/noties/markwon/Markwon.java index 9277688b..ce8f956a 100644 --- a/markwon-core/src/main/java/io/noties/markwon/Markwon.java +++ b/markwon-core/src/main/java/io/noties/markwon/Markwon.java @@ -141,21 +141,21 @@ public abstract class Markwon { * @see PrecomputedTextSetterCompat * @since 4.1.0 */ - public interface TextSetter { - /** - * @param textView TextView - * @param markdown prepared markdown - * @param bufferType BufferType specified when building {@link Markwon} instance - * via {@link Builder#bufferType(TextView.BufferType)} - * @param onComplete action to run when set-text is finished (required to call in order - * to execute {@link MarkwonPlugin#afterSetText(TextView)}) - */ - void setText( - @NonNull TextView textView, - @NonNull Spanned markdown, - @NonNull TextView.BufferType bufferType, - @NonNull Runnable onComplete); - } +public interface TextSetter { + /** + * @param textView TextView + * @param markdown prepared markdown + * @param bufferType BufferType specified when building {@link Markwon} instance + * via {@link Builder#bufferType(TextView.BufferType)} + * @param onComplete action to run when set-text is finished (required to call in order + * to execute {@link MarkwonPlugin#afterSetText(TextView)}) + */ + void setText( + @NonNull TextView textView, + @NonNull Spanned markdown, + @NonNull TextView.BufferType bufferType, + @NonNull Runnable onComplete); +} /** * Builder for {@link Markwon}.