markdown_viewer 0.4.0 markdown_viewer: ^0.4.0 copied to clipboard
A Markdown renderer for Flutter. Render Markdown String to rich text output.
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'package:flutter_prism/flutter_prism.dart';
import 'package:markdown_viewer/markdown_viewer.dart';
import 'extension.dart';
const markdown = r'''
## Markdown example
Hello **Markdown**!
### Highlights
- [x] ==100%== conform to CommonMark.
- [x] ==100%== conform to GFM.
- [x] Easy to implement syntax **highlighting**, for example `flutter_prism`:
```dart
// Dart language.
void main() {
print('Hello, World!');
}
```
- [x] Easy to custom, for example:
> This is a #custom_extension
- [x] Correct copy action.\
Flutter itself does not add line breaks between widgets, this library has
solved this problem except copying a table.
---
### Dependencies
| Name | Required|
|--|--:|
|`dart_markdown`|Yes|
|`flutter_prism`|No|
''';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'MarkdownViewer Demo',
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('MarkdownViewer Demo')),
body: SingleChildScrollView(
padding: const EdgeInsets.all(20),
child: MarkdownViewer(
markdown,
enableTaskList: true,
enableSuperscript: false,
enableSubscript: false,
enableFootnote: false,
enableImageSize: false,
enableKbd: false,
syntaxExtensions: [ExampleSyntax()],
highlightBuilder: (text, language, infoString) {
final prism = Prism(mouseCursor: SystemMouseCursors.text);
return prism.render(text, language ?? 'plain');
},
onTapLink: (href, title) {
print({href, title});
},
elementBuilders: [
ExampleBuilder(),
],
styleSheet: const MarkdownStyle(
listItemMarkerTrailingSpace: 12,
inlineCode: TextStyle(
fontFamily: 'RobotoMono',
),
codeBlock: TextStyle(
fontSize: 14,
letterSpacing: -0.3,
fontFamily: 'RobotoMono',
),
),
),
),
);
}
}