markdown library

Markdown to ANSI terminal rendering.

This library provides utilities to convert markdown text to ANSI-styled terminal output using artisanal's style system.

Usage

import 'package:artisanal/markdown.dart';

final styled = markdownToAnsi('''
# Hello World

This is **bold** and *italic* text.

- Item 1
- Item 2

> A blockquote

```dart
void main() {
  print('Hello!');
}

''');

print(styled);


## Customization

You can customize the rendering with [AnsiRendererOptions]:

```dart
final options = AnsiRendererOptions(
  h1Style: Style().bold().foreground(Colors.magenta),
  bulletChar: '-',
  hyperlinks: true,
);

print(markdownToAnsi(markdown, options: options));

Adaptive Themes

The renderer supports automatic theme selection based on terminal background:

final options = AnsiRendererOptions(
  hasDarkBackground: terminalTheme.hasDarkBackground ?? true,
);

For syntax highlighting, you can use AdaptiveChromaTheme:

final highlighter = SyntaxHighlighter.adaptive(
  adaptiveTheme: AdaptiveChromaTheme.draculaGithub,
  hasDarkBackground: terminalTheme.hasDarkBackground ?? true,
);

Classes

AdaptiveChromaTheme
An adaptive syntax highlighting theme that selects between light and dark variants based on terminal background.
AnsiRenderer
Renders markdown AST nodes to ANSI-styled terminal output.
AnsiRendererOptions
Configuration options for ANSI markdown rendering.
ChromaTheme
Configuration for syntax highlighting colors.
SyntaxHighlighter
Syntax highlighter that converts code to ANSI-styled terminal output.

Functions

highlightCodeString(String code, {String? language, ChromaTheme? theme}) String
Highlights code and returns ANSI-styled output.
markdownToAnsi(String markdown, {AnsiRendererOptions? options}) String
Converts a markdown string to ANSI-styled terminal text.