elegant_markdown 0.1.0
elegant_markdown: ^0.1.0 copied to clipboard
A high-quality Flutter Markdown + LaTeX renderer. Supports GFM, inline/block math formulas, syntax-highlighted code blocks, task lists, tables, and Light/Dark themes. Styled after Notion / GitHub.
elegant_markdown #
A high-quality Flutter component for rendering Markdown + LaTeX simultaneously.
Styled after Notion / GitHub β clean, readable, and fully customizable.
β¨ Features #
| Feature | Description |
|---|---|
| π Full Markdown | GFM β headings, bold/italic/strikethrough, lists, blockquotes, HR |
| π» Code Highlighting | Syntax highlighting via flutter_highlight with copy button |
| π’ LaTeX Math | Inline $...$, display $$...$$, multi-line $$ blocks via flutter_math_fork |
| βοΈ Task Lists | - [x] / - [ ] rendered as checkboxes |
| π Tables | GFM tables with border + padding |
| πΌοΈ Images | Network images with loading/error placeholders |
| π Links | Opens with url_launcher, custom handler supported |
| π Themes | Built-in Light & Dark, follows system brightness automatically |
| βοΈ Selectable | Optional text selection |
π¦ Installation #
Add to your pubspec.yaml:
dependencies:
elegant_markdown: ^0.1.0
Then run:
flutter pub get
π Quick Start #
import 'package:elegant_markdown/elegant_markdown.dart';
// Minimal usage β auto-follows system theme
ElegantMarkdown(
data: '# Hello\n\nThis is **bold** and $E=mc^2$.',
)
// Full API
ElegantMarkdown(
data: markdownText,
theme: ElegantMarkdownTheme.light(), // or .dark()
onTapLink: (url) => launchUrl(Uri.parse(url)),
selectable: true,
maxWidth: 800,
padding: const EdgeInsets.all(16),
)
π§© API Reference #
ElegantMarkdown #
| Property | Type | Default | Description |
|---|---|---|---|
data |
String |
required | Markdown source text |
theme |
ElegantMarkdownTheme? |
auto | Theme config; auto-detects system brightness if null |
onTapLink |
ValueChanged<String>? |
opens URL | Called when a link is tapped |
selectable |
bool |
false |
Enable text selection |
padding |
EdgeInsetsGeometry |
zero | Outer padding |
maxWidth |
double? |
null | Content max width (auto-centered) |
ElegantMarkdownTheme #
// Built-in presets
ElegantMarkdownTheme.light() // GitHub-inspired light theme
ElegantMarkdownTheme.dark() // GitHub-inspired dark theme
// Custom theme
ElegantMarkdownTheme(
brightness: Brightness.light,
background: Colors.white,
surface: Color(0xFFF6F8FA),
onSurface: Color(0xFF1F2328),
primary: Color(0xFF0969DA), // links, checkboxes
codeBackground: Color(0xFFF6F8FA),
codeForeground: Color(0xFF1F2328),
inlineCodeColor: Color(0xFFD63384), // inline `code` color
blockquoteBorder: Color(0xFFD0D7DE),
blockquoteBackground: Color(0xFFF6F8FA),
tableBorder: Color(0xFFD0D7DE),
tableHeaderBackground: Color(0xFFF6F8FA),
tableAltRowBackground: Color(0xFFFAFAFA),
divider: Color(0xFFD0D7DE),
highlightTheme: githubTheme, // from flutter_highlight
)
π Markdown Syntax Reference #
Text #
# H1 ## H2 ### H3
**bold** *italic* ~~strikethrough~~ `inline code`
Math (LaTeX) #
Inline: $E = mc^2$
Display (single line): $$\frac{a}{b}$$
Block (multi-line):
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$
Code Blocks #
```dart
void main() => runApp(const MyApp());
```
Supported language tags: dart, python, javascript, typescript,
java, kotlin, swift, rust, go, bash, yaml, json, sql, html, css, and more.
Task Lists #
- [x] Completed task
- [ ] Pending task
Tables #
| Column A | Column B |
|----------|----------|
| Cell 1 | Cell 2 |
π Theme Usage #
Explicit Theme #
ElegantMarkdown(
data: content,
theme: ElegantMarkdownTheme.dark(),
)
Auto Follow System Theme #
Simply omit theme β the widget reads Theme.of(context).brightness:
ElegantMarkdown(data: content)
Dynamic Toggle #
class _MyState extends State<MyPage> {
bool _isDark = false;
@override
Widget build(BuildContext context) {
return ElegantMarkdown(
data: content,
theme: _isDark
? ElegantMarkdownTheme.dark()
: ElegantMarkdownTheme.light(),
);
}
}
π§ Scrollable Document #
ElegantMarkdown renders as a non-scrolling body (MarkdownBody under the hood).
Wrap it in a SingleChildScrollView for scrollable documents:
SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: ElegantMarkdown(data: longDocument),
)
ποΈ Architecture #
elegant_markdown/
βββ lib/
β βββ elegant_markdown.dart # Public API entry point
β βββ src/
β βββ theme.dart # ElegantMarkdownTheme
β βββ syntax/
β β βββ math_syntax.dart # InlineMathSyntax + BlockMathSyntax
β βββ builders/
β βββ code_builder.dart # Code block with highlight + copy
β βββ math_builder.dart # LaTeX inline + block builders
βββ example/
βββ lib/main.dart # Runnable demo app
Key design decisions:
BlockMathBuilder.isBlockElement() = trueβ registersblockmathinto flutter_markdown's block tag list, preventing inline-context errors.- Custom
InlineMathSyntaxregex matches both$...$and$$...$$(single-line display) as inline nodes. - Custom
BlockMathSyntaxhandles multi-line$$...$$blocks as top-level block elements. builders['pre']intercepts all fenced code blocks; language is read fromclass="language-*"attribute.
π€ Contributing #
Contributions, issues, and pull requests are welcome!
See CONTRIBUTING.md or open an issue.
- Fork the repository
- Create your feature branch:
git checkout -b feat/awesome-feature - Commit changes:
git commit -m 'feat: add awesome feature' - Push:
git push origin feat/awesome-feature - Open a Pull Request
π License #
MIT Β© 2026 β See LICENSE for details.