elegant_markdown 0.1.0 copy "elegant_markdown: ^0.1.0" to clipboard
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 #

pub package pub points likes License: MIT

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 β€” registers blockmath into flutter_markdown's block tag list, preventing inline-context errors.
  • Custom InlineMathSyntax regex matches both $...$ and $$...$$ (single-line display) as inline nodes.
  • Custom BlockMathSyntax handles multi-line $$...$$ blocks as top-level block elements.
  • builders['pre'] intercepts all fenced code blocks; language is read from class="language-*" attribute.

🀝 Contributing #

Contributions, issues, and pull requests are welcome!
See CONTRIBUTING.md or open an issue.

  1. Fork the repository
  2. Create your feature branch: git checkout -b feat/awesome-feature
  3. Commit changes: git commit -m 'feat: add awesome feature'
  4. Push: git push origin feat/awesome-feature
  5. Open a Pull Request

πŸ“„ License #

MIT Β© 2026 β€” See LICENSE for details.

2
likes
120
points
28
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

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.

Topics

#markdown #latex #math #syntax-highlighting #text-rendering

License

MIT (license)

Dependencies

flutter, flutter_highlight, flutter_markdown, flutter_math_fork, markdown, url_launcher

More

Packages that depend on elegant_markdown