markdownx
Extended markdown parser with custom syntax for equations, dynamic protocols, and LaTeX math.
Features
- 🧮 Solvable Equations -
syntax - 📈 Graphable Equations -
syntax - 🔌 Custom Protocols - Define your own:
or[[Protocol:value]] - 📐 LaTeX Math - Inline
$...$and block$$...$$ - 🔍 Pure Dart - No Flutter dependency, works everywhere
Installation
dependencies:
markdownx: ^1.0.0
Quick Start
import 'package:markdownx/markdownx.dart';
void main() {
final markdown = '''
# Interactive Content

[[Simulation:pendulum]]

''';
final result = MarkdownxParser.parse(markdown);
print(result.equations.length); // 1
print(result.byProtocol('simulation')); // [simulation:pendulum]
print(result.byProtocol('video')); // [video:intro.mp4]
print(result.protocols); // {simulation, video}
}
Custom Protocols
Define any protocol you need! markdownx supports two syntaxes:
Image-style syntax

Bracket-style syntax
[[Protocol:value]]
Examples
# Simulations
[[Simulation:pendulum]]

# Videos

[[Video:tutorial.mp4]]
# Quizzes
[[Quiz:physics_101]]
# 3D Models

# Any custom protocol
[[MyProtocol:any_value_here]]
Working with protocols
final result = MarkdownxParser.parse(markdown);
// Get all custom elements
result.custom;
// Filter by protocol
result.byProtocol('simulation');
result.byProtocol('video');
result.byProtocol('quiz');
// Get all unique protocols
result.protocols; // {simulation, video, quiz, ...}
// Check for specific protocol
MarkdownxParser.hasProtocol(markdown, 'simulation');
Equations
Solvable Equations

- Display:
$F = ma$- The LaTeX to render - Equation:
F=m*a- Parseable equation for solving
Graphable Equations

Same as equations, but indicates the equation can be graphed.
LaTeX Math
Inline: $E = mc^2$
Block:
$$
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$
API Reference
MarkdownxParser
// Parse markdown and get all elements
final result = MarkdownxParser.parse(markdown);
// Access by type
result.equations; // All equations
result.custom; // All custom protocol elements
result.latex; // All LaTeX expressions
result.byProtocol('video'); // Filter by protocol
// Get all protocols used
result.protocols; // Set<String>
// Quick checks
MarkdownxParser.hasEquations(markdown);
MarkdownxParser.hasCustom(markdown);
MarkdownxParser.hasProtocol(markdown, 'simulation');
MarkdownxParser.hasLatex(markdown);
MarkdownxParser.hasCustomSyntax(markdown);
// Extract specific types
MarkdownxParser.extractEquations(markdown);
MarkdownxParser.extractCustom(markdown);
MarkdownxParser.extractByProtocol(markdown, 'video');
MarkdownxParser.extractLatex(markdown);
MarkdownxParser.getProtocols(markdown);
// Utility
MarkdownxParser.stripComments(markdown);
MarkdownxElement
final element = result.custom.first;
element.type; // MarkdownxElementType.custom
element.protocol; // 'simulation'
element.content; // 'pendulum'
element.display; // alt text (for image syntax)
element.start; // Start position in source
element.end; // End position in source
// Check protocol
element.isProtocol('simulation'); // true
Integration with markdown package
import 'package:markdown/markdown.dart';
import 'package:markdownx/markdownx.dart';
final html = markdownToHtml(
markdown,
inlineSyntaxes: markdownxInlineSyntaxes,
);
Element Types
| Type | Syntax | Description |
|---|---|---|
equation |
 |
Solvable equation |
graphEquation |
 |
Graphable equation |
custom |
 / [[Protocol:...]] |
Any custom protocol |
latex |
$...$ |
Inline LaTeX |
latexBlock |
$$...$$ |
Block LaTeX |
text |
- | Regular text |
License
MIT License - see LICENSE for details.
Libraries
- markdownx
- Extended markdown parser with custom syntax for equations, simulations, and LaTeX.