Markwon/docs/docs/v3/core/getting-started.md
2019-08-06 19:27:20 +03:00

1.8 KiB

Getting started

:::tip Installation Please follow installation instructions to learn how to add Markwon to your project :::

Quick one

This is the most simple way to set markdown to a TextView or any of its siblings:

// obtain an instance of Markwon
final Markwon markwon = Markwon.create(context);

// set markdown
markwon.setMarkdown(textView, "**Hello there!**");

The most simple way to obtain markdown to be applied somewhere else:

// obtain an instance of Markwon
final Markwon markwon = Markwon.create(context);

// parse markdown and create styled text
final Spanned markdown = markwon.toMarkdown("**Hello there!**");

// use it
Toast.makeText(context, markdown, Toast.LENGTH_LONG).show();

:::warning 3.x.x migration Starting with version Markwon no longer relies on static utility methods. To learn more about migrating existing applications refer to migration section. :::

Longer one

With explicit parse and render methods:

// obtain an instance of Markwon
final Markwon markwon = Markwon.create(context);

// parse markdown to commonmark-java Node
final Node node = markwon.parse("Are **you** still there?");

// create styled text from parsed Node
final Spanned markdown = markwon.render(node);

// use it on a TextView
markwon.setParsedMarkdown(textView, markdown);

// or a Toast
Toast.makeText(context, markdown, Toast.LENGTH_LONG).show();

No magic one

This section is kept due to historical reasons. Starting with version the amount of magic is reduced. To leverage your Markwon usage a concept of Plugin is introduced which helps to extend default behavior in a simple and no-breaking-the-flow manner. Head to the next section to know more.