A markdown renderer for Flutter.

Overview

Flutter Markdown

pub package Build Status

A markdown renderer for Flutter. It supports the original format, but no inline HTML.

Overview

The flutter_markdown package renders Markdown, a lightweight markup language, into a Flutter widget containing a rich text representation.

flutter_markdown is built on top of the Dart markdown package, which parses the Markdown into an abstract syntax tree (AST). The nodes of the AST are an HTML representation of the Markdown data.

Flutter Isn't a HTML Renderer

While this approach to creating a rich text representation of Markdown source text in Flutter works well, Flutter isn't a HTML renderer like a web browser. Markdown was developed by John Gruber in 2004 to allow users to turn readable, plain text content into rich text HTML. This close association with HTML allows for the injection of HTML into the Markdown source data. Markdown parsers generally ignore hand-tuned HTML and pass it through to be included in the generated HTML. This trick has allowed users to perform some customization or tweaking of the HTML output. A common HTML tweak is to insert HTML line-break elements <br /> in Markdown source to force additional line breaks not supported by the Markdown syntax. This HTML trick doesn't apply to Flutter. The flutter_markdown package doesn't support inline HTML.

Markdown Specifications and flutter_markdown Compliance

There are three seminal documents regarding Markdown syntax; the original Markdown syntax documentation specified by John Gruber, the CommonMark specification, and the GitHub Flavored Markdown specification.

The CommonMark specification brings order to and clarifies the Markdown syntax cases left ambiguous or unclear in the Gruber document. GitHub Flavored Markdown (GFM) is a strict superset of CommonMark used by GitHub.

The markdown package, and in extension, the flutter_markdown package, supports four levels of Markdown syntax; basic, CommonMark, GitHub Flavored, and GitHub Web. Basic, CommonMark, and GitHub Flavored adhere to the three Markdown documents, respectively. GitHub Web adds header ID and emoji support. The flutter_markdown package defaults to GitHub Flavored Markdown.

Getting Started

Using the Markdown widget is simple, just pass in the source markdown as a string:

Markdown(data: markdownSource);

If you do not want the padding or scrolling behavior, use the MarkdownBody instead:

MarkdownBody(data: markdownSource);

By default, Markdown uses the formatting from the current material design theme, but it's possible to create your own custom styling. Use the MarkdownStyle class to pass in your own style. If you don't want to use Markdown outside of material design, use the MarkdownRaw class.

Emoji Support

Emoji glyphs can be included in the formatted text displayed by the Markdown widget by either inserting the emoji glyph directly or using the inline emoji tag syntax in the source Markdown document.

Markdown documents using UTF-8 encoding can insert emojis, symbols, and other Unicode characters directly in the source document. Emoji glyphs inserted directly in the Markdown source data are treated as text and preserved in the formatted output of the Markdown widget. For example, in the following Markdown widget constructor, a text string with a smiley face emoji is passed in as the source Markdown data.

Markdown(
    controller: controller,
    selectable: true,
    data: 'Insert emoji here😀 ',
)

The resulting Markdown widget will contain a single line of text with the emoji preserved in the formatted text output.

The second method for including emoji glyphs is to provide the Markdown widget with a syntax extension for inline emoji tags. The Markdown package includes a syntax extension for emojis, EmojiSyntax. The default extension set used by the Markdown widget is the GitHub flavored extension set. This pre-defined extension set approximates the GitHub supported Markdown tags, providing syntax handlers for fenced code blocks, tables, auto-links, and strike-through. To include the inline emoji tag syntax while maintaining the default GitHub flavored Markdown behavior, define an extension set that combines EmojiSyntax with ExtensionSet.gitHubFlavored.

import 'package:markdown/markdown.dart' as md;

Markdown(
    controller: controller,
    selectable: true,
    data: 'Insert emoji :smiley: here',
    extensionSet: md.ExtensionSet(
      md.ExtensionSet.gitHubFlavored.blockSyntaxes,
      [md.EmojiSyntax(), ...md.ExtensionSet.gitHubFlavored.inlineSyntaxes],
    ),
)

Image Support

The Img tag only supports the following image locations:

  • From the network: Use a URL prefixed by either http:// or https://.

  • From local files on the device: Use an absolute path to the file, for example by concatenating the file name with the path returned by a known storage location, such as those provided by the path_provider plugin.

  • From image locations referring to bundled assets: Use an asset name prefixed by resource:. like resource:assets/image.png.

Verifying Markdown Behavior

Verifying Markdown behavior in other applications can often be useful to track down or identify unexpected output from the flutter_markdown package. Two valuable resources are the Dart Markdown Live Editor and the Markdown Live Preview. These two resources are dynamic, online Markdown viewers.

Markdown Resources

Here are some additional Markdown syntax resources:

You might also like...

A simple Flutter package that makes turning a FAB into a text field easy.

flutter_text_field_fab A simple Flutter widget that makes turning a FAB into a text field easy.

Jan 18, 2022

A low code editor with the full power of flutter.

A low code editor with the full power of flutter.

flutter_blossom 🌼 Low code editor with the full power of flutter. Think in flutter, watch your ideas come to life, plan ahead and let your creativity

Dec 2, 2021

Soft and gentle rich text editing for Flutter applications

Soft and gentle rich text editing for Flutter applications

Soft and gentle rich text editing for Flutter applications. Zefyrka is a fork of Zefyr package with the following improvements: support Flutter 2.0 op

Dec 21, 2022

A Flutter package provides some implementations of TextInputFormatter that format input with pre-defined patterns

A Flutter package provides some implementations of TextInputFormatter that format input with pre-defined patterns

A Flutter package provides some implementations of TextInputFormatter that format input with pre-defined patterns

Dec 31, 2022

Flutter App for beginner

i_am_rich A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

Nov 17, 2021

A powerful extended official text for Flutter, which supports Speical Text(Image,@somebody), Custom Background, Custom overFlow, Text Selection.

A powerful extended official text for Flutter, which supports Speical Text(Image,@somebody), Custom Background, Custom overFlow, Text Selection.

Extended official text to build special text like inline image or @somebody quickly,it also support custom background,custom over flow and custom selection toolbar and handles.

Jan 4, 2023

Rich coin project of flutter

rich_coin flutter实现RichCoin项目。 Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Nov 27, 2021

Arc Text Widget for Flutter

Arc Text Widget for Flutter

Flutter Arc Text Renders text along the arc. See demo. The story behind the plugin is here. Basic usage class MyApp extends StatelessWidget

Oct 18, 2021

Text Editor in Flutter for Android and iOS to help free write WYSIWYG HTML code

Text Editor in Flutter for Android and iOS to help free write WYSIWYG HTML code

Flutter Summernote Text Editor in Flutter for Android and iOS to help free write WYSIWYG HTML code based on Summernote 0.8.18 javascript wrapper. NOTI

Sep 12, 2022
Releases(0.6.1)
  • 0.6.1(Mar 19, 2021)

  • 0.6.0(Feb 17, 2021)

    • Null safety release
    • Added stylesheet option listBulletPadding
    • Fixed blockquote inline styling
    • Added onTapText handler for selectable text
    Source code(tar.gz)
    Source code(zip)
  • 0.5.0(Oct 21, 2020)

    • BREAKING CHANGE: MarkdownTapLinkCallback now has three parameters, not one, exposing more information about a tapped link.
      • Note for upgraders, the old single parameter href is now the second parameter to match the specification.
    • Android example upgraded
    • Test coverage updated to match GitHub Flavoured Markdown and CommonMark
    • Handle links with empty descriptions
    • Handle empty rows in tables
    Source code(tar.gz)
    Source code(zip)
  • 0.4.4(Sep 2, 2020)

    • Fix handling of newline character in blockquote
    • Add new example demo
    • Use the start attribute in ordered list to set the first number
    • Revert changes made in PR #235 (which broke newline handling)
    Source code(tar.gz)
    Source code(zip)
  • 0.4.3(Aug 3, 2020)

    • Fix merging of MarkdownStyleSheets
    • Fix if not provided in MarkdownStyleSheet textScaleFactor uses default value of 1.0 instead using the textScaleFactor of the nearest MediaQuery
    Source code(tar.gz)
    Source code(zip)
  • 0.4.2(Jun 15, 2020)

  • 0.4.1(Jun 13, 2020)

  • 0.4.0(Jun 13, 2020)

  • 0.3.5(Apr 18, 2020)

  • 0.3.4(Apr 18, 2020)

  • 0.3.3(Apr 18, 2020)

  • 0.3.2(Nov 26, 2019)

    • Uplift package:markdown dependency version to enable deleting HTML unescape URI workaround
    • Explictly state that Flutter 1.10.7 is the minimum supported Flutter version in the library pubspec.yaml.
    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Nov 26, 2019)

    • Expose tableColumnWidth
    • Add MarkdownStyleSheet.fromCupertinoTheme
    • Fix MarkdownStyleSheet.blockquote
    • Flutter for web support
    • Add physics and shrinkWrap to Markdown widget
    • Add MarkdownBody.fitContent
    • Support select text to copy
    • Fix list bullet alignment
    • HTML unescape URIs (temporary workaround for dart-lang/markdown #272)
    • Rebuilt example/android and example/ios directories

    Note: this version has an implicit minimum supported version of Flutter 1.10.7. See flutter/flutter_markdown issue #156 for more detail.

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Oct 23, 2019)

  • 0.1.3(Feb 28, 2018)

  • 0.0.10(Sep 29, 2017)

  • 0.0.9(Aug 8, 2017)

Owner
Flutter
Flutter
Flutter textfield validation lets you validate different textform fields in your Flutter app

Flutter textfield validation lets you validate different textform fields in your Flutter app

World-Package 2 Sep 15, 2022
A masked text for Flutter.

flutter_masked_text Masked text input for flutter. Alert Hi guys! Unfortunately, I'm not developing mobile anymore. This repo will not receive updates

Ben-hur Santos Ott 264 Dec 21, 2022
Soft and gentle rich text editing for Flutter applications.

About Zefyr Soft and gentle rich text editing for Flutter applications. You are viewing early dev preview version of this package which is no longer a

Memspace 2.2k Jan 8, 2023
Flutter widget that automatically resizes text to fit perfectly within its bounds.

Flutter widget that automatically resizes text to fit perfectly within its bounds. Show some ❤️ and star the repo to support the project Resources: Do

Simon Leier 1.8k Jan 3, 2023
A Flutter package to parse text and make them into linkified text widget

?? Flutter Parsed text A Flutter package to parse text and extract parts using predefined types like url, phone and email and also supports Regex. Usa

Fayeed Pawaskar 213 Dec 27, 2022
A Flutter Package to render Mathematics, Physics and Chemistry Equations based on LaTeX

flutter_tex Contents About Demo Video Screenshots How to use? Android iOS Web Examples Quick Example TeXView Document TeXView Markdown TeXView Quiz Te

Shahzad Akram 219 Jan 5, 2023
flutter 中文排版,支持分页上下对齐 两端对齐 翻页动画

text_composition flutter 中文排版 分页 上下对齐 两端对齐 多栏布局 弃用richText,使用Canvas,精确定位绘图位置,消除字体对排版影响 视频与截图 demo https://github.com/mabDc/text_composition/releases/t

西红柿大芝麻 50 Nov 3, 2022
Flutter Tutorial - PDF Viewer - Asset, File, Network & Firebase

Flutter Tutorial - PDF Viewer - Asset, File, Network & Firebase Use the Flutter PDF Viewer to download PDF documents and display them within your Flut

Johannes Milke 36 Dec 9, 2022
Create an AutoComplete TextField to search JSON data based on suggestions in Flutter.

Flutter Tutorial - AutoComplete TextField & AutoComplete Search Create an AutoComplete TextField to search JSON data based on suggestions in Flutter.

Johannes Milke 32 Oct 23, 2022
Flutter phone number input

phone_form_field Flutter phone input integrated with flutter internationalization Features Totally cross platform, this is a dart only package / depen

cedvdb 38 Dec 31, 2022