Convert Figma logo to code with AI

noties logoMarkwon

Android markdown library (no WebView)

2,740
309
2,740
71

Top Related Projects

Java library for parsing and rendering CommonMark (Markdown)

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.

Android平台下的富文本解析器,支持Html和Markdown

Quick Overview

Markwon is a powerful Android library for rendering Markdown as native views. It provides a flexible and extensible API for parsing and displaying Markdown content in Android applications, with support for various Markdown flavors and custom extensions.

Pros

  • Highly customizable and extensible
  • Supports various Markdown flavors and plugins
  • Efficient rendering with native Android views
  • Active development and community support

Cons

  • Learning curve for advanced customizations
  • Limited built-in theming options
  • Potential performance impact for large Markdown documents
  • Some advanced features require additional dependencies

Code Examples

  1. Basic Markdown rendering:
val markwon = Markwon.create(context)
val textView = findViewById<TextView>(R.id.textView)
markwon.setMarkdown(textView, "# Hello, Markwon!")
  1. Using plugins:
val markwon = Markwon.builder(context)
    .usePlugin(TablePlugin.create(context))
    .usePlugin(TaskListPlugin.create(context))
    .build()

markwon.setMarkdown(textView, markdownWithTablesAndTasks)
  1. Custom image loading:
val glideStore = GlideImagesPlugin.create(context)
val markwon = Markwon.builder(context)
    .usePlugin(GlideImagesPlugin.create(glideStore))
    .build()

markwon.setMarkdown(textView, markdownWithImages)
  1. Handling clicks on links:
val markwon = Markwon.builder(context)
    .usePlugin(object : AbstractMarkwonPlugin() {
        override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
            builder.linkResolver { view, link ->
                // Handle link click
                Toast.makeText(view.context, link, Toast.LENGTH_SHORT).show()
            }
        }
    })
    .build()

markwon.setMarkdown(textView, markdownWithLinks)

Getting Started

To use Markwon in your Android project, add the following dependency to your app's build.gradle file:

dependencies {
    implementation 'io.noties.markwon:core:4.6.2'
}

Then, in your Activity or Fragment, create a Markwon instance and use it to render Markdown:

import io.noties.markwon.Markwon

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val markwon = Markwon.create(this)
        val textView = findViewById<TextView>(R.id.textView)
        markwon.setMarkdown(textView, "# Welcome to Markwon\n\nThis is **Markdown** rendered with _Markwon_!")
    }
}

This basic setup will allow you to render simple Markdown in your Android app. For more advanced features and customizations, refer to the Markwon documentation.

Competitor Comparisons

Java library for parsing and rendering CommonMark (Markdown)

Pros of commonmark-java

  • Pure Java implementation, suitable for server-side and non-Android Java applications
  • Follows the CommonMark specification strictly, ensuring high compatibility
  • Extensible parser and renderer architecture for custom syntax and output formats

Cons of commonmark-java

  • Limited built-in support for advanced Markdown features (e.g., tables, task lists)
  • Requires additional setup for Android integration compared to Markwon
  • Less focus on UI rendering and customization for mobile applications

Code Comparison

commonmark-java:

Parser parser = Parser.builder().build();
Node document = parser.parse("This is *Markdown*");
HtmlRenderer renderer = HtmlRenderer.builder().build();
String html = renderer.render(document);

Markwon:

Markwon markwon = Markwon.create(context);
TextView textView = findViewById(R.id.text_view);
markwon.setMarkdown(textView, "This is *Markdown*");

Summary

While commonmark-java excels in server-side applications and strict CommonMark compliance, Markwon is tailored for Android development with built-in UI rendering capabilities. commonmark-java offers more flexibility for custom parsing and rendering, but Markwon provides a more streamlined experience for mobile developers working with Markdown in Android applications.

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.

Pros of flexmark-java

  • More comprehensive Markdown parsing and rendering capabilities
  • Highly customizable with numerous extension options
  • Better suited for server-side Markdown processing

Cons of flexmark-java

  • Larger library size and potentially higher memory footprint
  • Steeper learning curve due to its extensive feature set
  • Not specifically optimized for Android development

Code Comparison

Markwon:

Markwon markwon = Markwon.create(context);
markwon.setMarkdown(textView, "# Hello, Markdown!");

flexmark-java:

Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();
Node document = parser.parse("# Hello, Markdown!");
String html = renderer.render(document);

Summary

Markwon is specifically designed for Android, offering a simpler API and better performance on mobile devices. It's ideal for rendering Markdown in Android apps with minimal setup.

flexmark-java provides a more powerful and flexible Markdown processing solution, suitable for a wide range of applications beyond Android. It offers extensive customization options but may require more setup and resources.

Choose Markwon for Android-specific projects with straightforward Markdown needs, and flexmark-java for more complex Markdown processing requirements or non-Android environments.

Android平台下的富文本解析器,支持Html和Markdown

Pros of RichText

  • Simpler implementation for basic rich text rendering
  • Supports HTML tags out of the box
  • Lighter weight library with fewer dependencies

Cons of RichText

  • Less extensive Markdown support compared to Markwon
  • Limited customization options for rendering
  • Fewer advanced features like syntax highlighting or LaTeX support

Code Comparison

Markwon:

val markwon = Markwon.create(context)
markwon.setMarkdown(textView, "# Hello, Markdown!")

RichText:

RichText.fromMarkdown("# Hello, Markdown!")
       .into(textView);

Both libraries offer simple ways to render Markdown, but Markwon provides more extensive customization options and features. RichText is more straightforward for basic use cases but may lack advanced functionality for complex Markdown rendering needs. Markwon is generally considered more powerful and flexible, while RichText is simpler and lighter weight. The choice between them depends on the specific requirements of your project and the level of Markdown support needed.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

logo

Markwon

Build

Markwon is a markdown library for Android. It parses markdown following commonmark-spec with the help of amazing commonmark-java library and renders result as Android-native Spannables. No HTML is involved as an intermediate step. No WebView is required. It's extremely fast, feature-rich and extensible.

It gives ability to display markdown in all TextView widgets (TextView, Button, Switch, CheckBox, etc), Toasts and all other places that accept Spanned content. Library provides reasonable defaults to display style of a markdown content but also gives all the means to tweak the appearance if desired. All markdown features listed in commonmark-spec are supported (including support for inlined/block HTML code, markdown tables, images and syntax highlight).

Markwon comes with a sample application. It is a collection of library usages that comes with search and source code for each code sample.

Since version 4.2.0 Markwon comes with an editor to highlight markdown input as user types (for example in EditText).

Installation

stable snapshot

implementation "io.noties.markwon:core:${markwonVersion}"

Full list of available artifacts is present in the install section of the documentation web-site.

Please visit documentation web-site for further reference.

You can find previous version of Markwon in 2.x.x and 3.x.x branches

Supported markdown features:

  • Emphasis (*, _)
  • Strong emphasis (**, __)
  • Strike-through (~~)
  • Headers (#{1,6})
  • Links ([]() && [][])
  • Images
  • Thematic break (---, ***, ___)
  • Quotes & nested quotes (>{1,})
  • Ordered & non-ordered lists & nested ones
  • Inline code
  • Code blocks
  • Tables (with limitations)
  • Syntax highlight
  • LaTeX formulas
  • HTML
    • Emphasis (<i>, <em>, <cite>, <dfn>)
    • Strong emphasis (<b>, <strong>)
    • SuperScript (<sup>)
    • SubScript (<sub>)
    • Underline (<u>, ins)
    • Strike-through (<s>, <strike>, <del>)
    • Link (a)
    • Lists (ul, ol)
    • Images (img will require configured image loader)
    • Blockquote (blockquote)
    • Heading (h1, h2, h3, h4, h5, h6)
    • there is support to render any HTML tag
  • Task lists:
  • Not done
    • Done with X
    • and or small x

Screenshots

Taken with default configuration (except for image loading) in sample app:

By default configuration uses TextView textColor for styling, so changing textColor changes style


Documentation

Please visit documentation web-site for reference

Consulting

Paid consulting is available. Please reach me out at markwon+consulting[at]noties.io to discuss your idea or a project


Demo

Based on this cheatsheet


Headers


Header 1

Header 2

Header 3

Header 4

Header 5
Header 6

Emphasis

Emphasis, aka italics, with asterisks or underscores.

Strong emphasis, aka bold, with asterisks or underscores.

Combined emphasis with asterisks and underscores.

Strikethrough uses two tildes. Scratch this.


Lists

  1. First ordered list item
  2. Another item
  • Unordered sub-list.
  1. Actual numbers don't matter, just that it's a number

  2. Ordered sub-list

  3. And another item.

    You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).

    To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

  • Unordered list can use asterisks
  • Or minuses
  • Or pluses

Links

I'm an inline-style link

I'm a reference-style link

I'm a relative reference to a repository file

You can use numbers for reference-style link definitions

Or leave it empty and use the link text itself.


Code

Inline code has back-ticks around it.

var s = "JavaScript syntax highlighting";
alert(s);
s = "Python syntax highlighting"
print s
/**
 * Helper method to obtain a Parser with registered strike-through &amp; table extensions
 * &amp; task lists (added in 1.0.1)
 *
 * @return a Parser instance that is supported by this library
 * @since 1.0.0
 */
@NonNull
public static Parser createParser() {
  return new Parser.Builder()
      .extensions(Arrays.asList(
          StrikethroughExtension.create(),
          TablesExtension.create(),
          TaskListExtension.create()
      ))
      .build();
}
<ScrollView
  android:id="@+id/scroll_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginTop="?android:attr/actionBarSize">

  <TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="16dip"
    android:lineSpacingExtra="2dip"
    android:textSize="16sp"
    tools:text="yo\nman" />

</ScrollView>
No language indicated, so no syntax highlighting.
But let's throw in a <b>tag</b>.

Tables

Colons can be used to align columns.

TablesAreCool
col 3 isright-aligned$1600
col 2 iscentered$12
zebra stripesare neat$1

There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.

MarkdownLessPretty
Stillrendersnicely
123

Blockquotes

Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.

Quote break.

This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can put Markdown into a blockquote.

Nested quotes

Hello!

And to you!


Inline HTML

<u><i>H<sup>T<sub>M</sub></sup><b><s>L</s></b></i></u>

HTML


Horizontal Rule

Three or more...


Hyphens (-)


Asterisks (*)


Underscores (_)

License

  Copyright 2019 Dimitry Ivanov (legal@noties.io)

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.