1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
(window.webpackJsonp=window.webpackJsonp||[]).push([[24],{277:function(t,n,a){"use strict";a.r(n);var s=a(0),e=Object(s.a)({},function(){var t=this,n=t.$createElement,a=t._self._c||n;return a("div",{staticClass:"content"},[t._m(0),t._v(" "),a("LegacyWarning"),t._v(" "),t._m(1),t._v(" "),t._m(2),t._v(" "),t._m(3),t._m(4),t._v(" "),t._m(5),t._m(6),t._v(" "),a("p",[t._v("When you need to customize markdown parsing/rendering you can use "),a("router-link",{attrs:{to:"/docs/v2/configure.html"}},[t._v("SpannableConfiguration")]),t._v(":")],1),t._v(" "),t._m(7),t._m(8),t._v(" "),a("p",[t._v("In order to understand how previous examples work, let's break them down:")]),t._v(" "),a("ul",[a("li",[t._v("construct a "),a("code",[t._v("Parser")]),t._v(" (see: "),a("Link",{attrs:{name:"commonmark-java"}}),t._v(") and parse markdown")],1),t._v(" "),t._m(9),t._v(" "),t._m(10),t._v(" "),a("li",[t._v("prepares TextView to display images, tables and links")]),t._v(" "),a("li",[t._v("sets text")])]),t._v(" "),t._m(11),t._v(" "),t._m(12),t._v(" "),t._m(13),t._v(" "),t._m(14),t._v(" "),t._m(15),a("div",{staticClass:"tip custom-block"},[a("p",{staticClass:"custom-block-title"},[t._v("Note")]),t._v(" "),a("p",[t._v("If you are having trouble with "),a("code",[t._v("LinkMovementMethod")]),t._v(" you can use\n"),a("code",[t._v("Markwon.setText(textView, markdown, movementMethod)")]),t._v(" method "),a("Badge",{attrs:{text:"1.0.6"}}),t._v(" to specify "),a("em",[t._v("no")]),t._v(" movement\nmethod (aka "),a("code",[t._v("null")]),t._v(") or own implementation. As an alternative to the system "),a("code",[t._v("LinkMovementMethod")]),t._v("\nyou can use "),a("a",{attrs:{href:"https://github.com/saket/Better-Link-Movement-Method",target:"_blank",rel:"noopener noreferrer"}},[t._v("Better-Link-Movement-Method"),a("OutboundLink")],1),t._v(".\nPlease note that "),a("code",[t._v("Markwon.setText")]),t._v(" method expects "),a("em",[t._v("parsed")]),t._v(" markdown as the second argument.")],1)])],1)},[function(){var t=this.$createElement,n=this._self._c||t;return n("h1",{attrs:{id:"getting-started"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#getting-started","aria-hidden":"true"}},[this._v("#")]),this._v(" Getting started")])},function(){var t=this.$createElement,n=this._self._c||t;return n("h2",{attrs:{id:"quick-one"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#quick-one","aria-hidden":"true"}},[this._v("#")]),this._v(" Quick one")])},function(){var t=this.$createElement,n=this._self._c||t;return n("p",[this._v("This is the most simple way to set markdown to a "),n("code",[this._v("TextView")]),this._v(" or any of its siblings:")])},function(){var t=this,n=t.$createElement,a=t._self._c||n;return a("div",{staticClass:"language-java extra-class"},[a("pre",{pre:!0,attrs:{class:"language-java"}},[a("code",[t._v("Markwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("setMarkdown")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("textView"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"**Hello there!**"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])},function(){var t=this.$createElement,n=this._self._c||t;return n("p",[this._v("The most simple way to obtain markdown to be applied "),n("em",[this._v("somewhere")]),this._v(" else:")])},function(){var t=this,n=t.$createElement,a=t._self._c||n;return a("div",{staticClass:"language-java extra-class"},[a("pre",{pre:!0,attrs:{class:"language-java"}},[a("code",[a("span",{attrs:{class:"token comment"}},[t._v("// parsed and styled markdown")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("final")]),t._v(" CharSequence markdown "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" Markwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("markdown")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("context"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"**Hello there!**"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token comment"}},[t._v("// use it")]),t._v("\nToast"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("makeText")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("context"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" markdown"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Toast"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("LENGTH_LONG"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("show")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])},function(){var t=this.$createElement,n=this._self._c||t;return n("h2",{attrs:{id:"longer-one"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#longer-one","aria-hidden":"true"}},[this._v("#")]),this._v(" Longer one")])},function(){var t=this,n=t.$createElement,a=t._self._c||n;return a("div",{staticClass:"language-java extra-class"},[a("pre",{pre:!0,attrs:{class:"language-java"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("final")]),t._v(" SpannableConfiguration configuration "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" SpannableConfiguration"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("builder")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("context"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("asyncDrawableLoader")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("AsyncDrawableLoader"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("create")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("build")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nMarkwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("setMarkdown")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("textView"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" configuration"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"Are **you** still there?"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token keyword"}},[t._v("final")]),t._v(" CharSequence markdown "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" Markwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("markdown")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("configuration"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"Are **you** still there?"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nToast"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("makeText")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("context"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" markdown"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Toast"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("LENGTH_LONG"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("show")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])},function(){var t=this.$createElement,n=this._self._c||t;return n("h2",{attrs:{id:"no-magic-one"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#no-magic-one","aria-hidden":"true"}},[this._v("#")]),this._v(" No magic one")])},function(){var t=this.$createElement,n=this._self._c||t;return n("li",[this._v("construct a "),n("code",[this._v("SpannableConfiguration")]),this._v(" (if it's not provided)")])},function(){var t=this.$createElement,n=this._self._c||t;return n("li",[n("em",[this._v("render")]),this._v(" parsed markdown to Spannable (via "),n("code",[this._v("SpannableRenderer")]),this._v(")")])},function(){var t=this.$createElement,n=this._self._c||t;return n("p",[this._v("This flow answers the most simple usage of displaying markdown: one shot parsing\n& configuration of relatively small markdown chunks. If your markdown contains\na lot of text or you plan to display multiple UI widgets with markdown you might\nconsider "),n("em",[this._v("stepping in")]),this._v(" and taking control of this flow.")])},function(){var t=this.$createElement,n=this._self._c||t;return n("p",[this._v("The candidate requirements to "),n("em",[this._v("step in")]),this._v(":")])},function(){var t=this,n=t.$createElement,a=t._self._c||n;return a("ul",[a("li",[t._v("parsing and processing of parsed markdown in a background thread")]),t._v(" "),a("li",[t._v("reusing "),a("code",[t._v("Parser")]),t._v(" and/or "),a("code",[t._v("SpannableConfiguration")]),t._v(" between multiple calls")]),t._v(" "),a("li",[t._v("ignore images or tables specific logic (you know that markdown won't contain them)")])])},function(){var t=this.$createElement,n=this._self._c||t;return n("p",[this._v("So, if we expand "),n("code",[this._v("Markwon.setMarkdown(textView, markdown)")]),this._v(" method we will see the following:")])},function(){var t=this,n=t.$createElement,a=t._self._c||n;return a("div",{staticClass:"language-java extra-class"},[a("pre",{pre:!0,attrs:{class:"language-java"}},[a("code",[a("span",{attrs:{class:"token comment"}},[t._v("// create a Parser instance (can be done manually)")]),t._v("\n"),a("span",{attrs:{class:"token comment"}},[t._v("// internally creates default Parser instance & registers `strike-through` & `tables` extension")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("final")]),t._v(" Parser parser "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" Markwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("createParser")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token comment"}},[t._v("// core class to display markdown, can be obtained via this method,")]),t._v("\n"),a("span",{attrs:{class:"token comment"}},[t._v("// which creates default instance (no images handling though),")]),t._v("\n"),a("span",{attrs:{class:"token comment"}},[t._v("// or via `builder` method, which lets you to configure this instance")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("final")]),t._v(" SpannableConfiguration configuration "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" SpannableConfiguration"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("create")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("context"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token keyword"}},[t._v("final")]),t._v(" SpannableRenderer renderer "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),a("span",{attrs:{class:"token class-name"}},[t._v("SpannableRenderer")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token keyword"}},[t._v("final")]),t._v(" Node node "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" parser"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("parse")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("markdown"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("final")]),t._v(" CharSequence text "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" renderer"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("render")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("configuration"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" node"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token comment"}},[t._v("// for links in markdown to be clickable")]),t._v("\ntextView"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("setMovementMethod")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("LinkMovementMethod"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("getInstance")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token comment"}},[t._v("// we need these due to the limited nature of Spannables to invalidate TextView")]),t._v("\nMarkwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("unscheduleDrawables")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("textView"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nMarkwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("unscheduleTableRows")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("textView"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token comment"}},[t._v("// @since 2.0.1 we must measure ordered list items _before_ they are rendered")]),t._v("\nOrderedListItemSpan"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("measure")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("view"),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" text"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\ntextView"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("setText")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("text"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nMarkwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("scheduleDrawables")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("textView"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nMarkwon"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("scheduleTableRows")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("textView"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])}],!1,null,null,null);e.options.__file="getting-started.md";n.default=e.exports}}]); |