Rich Markdown
A Flutter package for rendering Markdown, LaTeX equations, and HTML content in a single reusable widget. Designed for AI chat applications, streaming responses, educational apps, documentation viewers, and content-rich mobile applications.
โจ Features
- ๐ Markdown Rendering โ Headings, paragraphs, bold, italic, strikethrough, lists, blockquotes, links, and GitHub Flavored Markdown.
- ๐งฎ LaTeX Support โ Render inline and block mathematical expressions using
flutter_math_fork. - ๐ HTML Rendering โ Display HTML content with custom LaTeX tags.
- ๐ฌ AI Chat Ready โ Designed to support Markdown and math in AI-generated responses.
- โก Streaming-Friendly โ Supports progressively updated content as responses arrive.
- ๐ Link Callbacks โ Handle link taps with your own navigation logic.
- ๐จ Custom Styling โ Customize text size, color, font family, and layout.
- ๐งฉ Simple API โ One widget for multiple content formats.
๐ฆ Installation
Add the package to your pubspec.yaml:
dependencies:
rich_markdown: ^1.0.0
Then run:
flutter pub get
๐ Quick Start
Import the package:
import 'package:flutter/material.dart';
import 'package:rich_markdown/rich_markdown.dart';
Render Markdown content:
const content = r'''
# Hello, Rich Markdown!
This is **bold text** and *italic text*.
Inline equation: \(E = mc^2\)
Block equation:
$$
\int_0^1 x^2\,dx = \frac{1}{3}
$$
''';
RichMarkdownView(
data: content,
type: ContentType.markdown,
textStyle: const TextStyle(
fontSize: 16,
height: 1.5,
),
)
๐ธ Screenshots
1. Markdown Rendering

Displays Markdown formatting, headings, lists, links, and blockquotes.
2. Inline LaTeX

Render mathematical expressions directly within paragraphs.
3. Block LaTeX

Display equations such as integrals, fractions, summations, and quadratic formulas.
4. HTML Rendering

Render HTML elements, including paragraphs, lists, emphasis, links, and supported custom math tags.
5. Code and LaTeX Handling

Test code blocks and inline code containing LaTeX-like expressions.
6. Currency and Symbols

Test currency values, escaped dollar signs, and inline mathematical expressions.
7. Incomplete Equations

Test how unfinished equations are handled while content is being generated.
๐ฌ AI Streaming Demo
Watch Rich Markdown render progressively updated AI-style responses containing Markdown and LaTeX.

The animation demonstrates simulated streaming in the example application. Actual streaming behavior depends on how your application supplies updated content and how incomplete Markdown and LaTeX expressions are handled.
๐ ๏ธ Usage
Markdown
RichMarkdownView(
data: '# Welcome\n\nThis is **Markdown**.',
type: ContentType.markdown,
)
LaTeX
Use raw strings to preserve LaTeX backslashes:
RichMarkdownView(
data: r'\int_0^\infty e^{-x}\,dx = 1',
type: ContentType.latex,
)
The latex content type renders the supplied expression in display math mode.
HTML
RichMarkdownView(
data: '''
<h2>Hello</h2>
<p>This is <strong>HTML</strong>.</p>
''',
type: ContentType.html,
)
HTML with LaTeX
The package supports custom tex and texblock tags containing Base64-encoded LaTeX.
RichMarkdownView(
data: '''
<p>Inline math: <tex>Uj1hXjI=</tex></p>
''',
type: ContentType.html,
)
The encoded example represents R=a^2.
Custom Styling
RichMarkdownView(
data: '# Custom Content\n\nStyled text.',
type: ContentType.markdown,
textStyle: const TextStyle(
fontSize: 18,
height: 1.6,
color: Colors.black87,
),
shrinkWrap: true,
)
Handle Link Taps
RichMarkdownView(
data: '[Visit Flutter](https://flutter.dev)',
onLinkTap: (url) {
debugPrint('Tapped link: $url');
// Add your navigation or URL-launching logic here.
},
)
๐ API Reference
RichMarkdownView
| Parameter | Type | Default | Description |
|---|---|---|---|
data |
String |
Required | Content to render |
type |
ContentType |
ContentType.markdown |
Content format |
textStyle |
TextStyle? |
null |
Text styling |
onLinkTap |
void Function(String? url)? |
null |
Link tap callback |
shrinkWrap |
bool |
true |
Controls HTML content shrink wrapping |
ContentType
| Value | Description |
|---|---|
ContentType.markdown |
Renders Markdown and supported LaTeX expressions |
ContentType.latex |
Renders the input as a block LaTeX expression |
ContentType.html |
Renders HTML with supported custom math tags |
๐งช Example App
Explore the example application to try different content types and test mathematical expressions.
git clone https://github.com/rohit-bon/rich_markdown.git
cd rich_markdown/example
flutter pub get
flutter run
Replace YOUR_USERNAME with your GitHub username.
๐งฐ Built With
๐บ๏ธ Roadmap
More comprehensive Markdown and LaTeX parsing testsImproved handling of incomplete equations during streamingAdditional HTML and Markdown customizationPerformance improvements for frequently updated AI responsesMore examples and documentation
๐ค Contributing
Contributions, bug reports, and feature requests are welcome.
- Fork the repository.
- Create a feature branch.
- Implement your changes and add tests.
- Submit a pull request.
๐ License
This project is distributed under the MIT License. See the LICENSE file for details.
โญ Support
If you find Rich Markdown useful, consider giving the project a star on GitHub and sharing feedback through issues or pull requests.