markd 0.11.5+3
markd: ^0.11.5+3 copied to clipboard
A fork of dart-lang's markdown
A fork of dart-markdown for easy customization of Markdown syntaxes.
Differences
LinkMapperintroduced to simplify the customization ofLinkSyntax.InlineParser.beandBlockParser.beintroduced for using fully customized line syntaxes. They are used in pair if all parsing shares the same set of syntaxes.BlockParser.safeBlockParsersintroduced for not parsing HTML tags at all.Document's constructor introduced additional arguments,options,blockParserBuilderandinlineParserBuilderfor easy customization.- Attribute's names are not sorted
InlineSyntax.matchintroduced for easy overriding.InlineSyntax's constructor introduces the caseSensitive argumentFencedCodeBlockSyntax.getLanguageClassintroduced for generating custom CSS classTableSyntax.processCellContentintroduced for pre-processing cell's content- Allow a link containing parenthesis and quotes
Resources
Customizations
Who Uses
- Quire - a simple, collaborative, multi-level task management tool.
Introduction #
A portable Markdown library written in Dart. It can parse Markdown into HTML on both the client and server.
Play with it at dart-lang.github.io/markdown.
Usage #
import 'package:markd/markdown.dart';
void main() {
print(markdownToHtml('Hello *Markdown*'));
//=> <p>Hello <em>Markdown</em></p>
}
Syntax extensions #
A few Markdown extensions, beyond what was specified in the original
Perl Markdown implementation, are supported. By default, the ones supported
in CommonMark are enabled. Any individual extension can be enabled by
specifying an Array of extension syntaxes in the blockSyntaxes or
inlineSyntaxes argument of markdownToHtml.
The currently supported inline extension syntaxes are:
new InlineHtmlSyntax()- approximately CommonMark's definition of "Raw HTML".
The currently supported block extension syntaxes are:
const FencedCodeBlockSyntax()- Code blocks familiar to Pandoc and PHP Markdown Extra users.const HeaderWithIdSyntax()- ATX-style headers have generated IDs, for link anchors (akin to Pandoc'sauto_identifiers).const SetextHeaderWithIdSyntax()- Setext-style headers have generated IDs for link anchors (akin to Pandoc'sauto_identifiers).const TableSyntax()- Table syntax familiar to GitHub, PHP Markdown Extra, and Pandoc users.
For example:
import 'package:markd/markdown.dart';
void main() {
print(markdownToHtml('Hello <span class="green">Markdown</span>',
inlineSyntaxes: [new InlineHtmlSyntax()]));
//=> <p>Hello <span class="green">Markdown</span></p>
}
Extension Sets #
To make extension management easy, you can also just specify an extension set.
Both markdownToHtml() and new Document() accept an extensionSet named
parameter. Right now there are two extension sets:
-
ExtensionSet.noneincludes no extensions. With no extensions, Markdown documents will be parsed closely to how they might be parsed by the original Perl Markdown implementation. -
ExtensionSet.commonMarkincludes two extensions so far, which bring this package's Markdown parsing closer to what is found in the CommonMark spec:new InlineHtmlSyntax()const FencedCodeBlockSyntax()
-
ExtensionSet.gitHubincludes five extensions:new InlineHtmlSyntax()const FencedCodeBlockSyntax()const HeaderWithIdSyntax(), which addsidattributes to ATX-style headers, for easy intra-document linking.const SetextHeaderWithIdSyntax(), which addsidattributes to Setext-style headers, for easy intra-document linking.const TableSyntax()
Custom syntax extensions #
You can create and use your own syntaxes.
import 'package:markd/markdown.dart';
void main() {
var syntaxes = [new TextSyntax('nyan', sub: '~=[,,_,,]:3')];
print(markdownToHtml('nyan', inlineSyntaxes: syntaxes));
//=> <p>~=[,,_,,]:3</p>
}
### HTML Sanitization
This package offers no features in the way of HTML sanitization. Read Estevão
Soares dos Santos's great article, ["Markdown's XSS Vulnerability (and how to
mitigate it)"], to learn more.
The authors recommend that you perform any necessary sanitization on the
resulting HTML, for example via `dart:html`'s [NodeValidator].
CommonMark compliance #
This package contains a number of files in the tool directory for tracking
compliance with CommonMark.
Updating CommonMark stats when changing the implementation
- Update the library and test code, making sure that tests still pass.
- Run
dart tool/stats.dart --update-filesto update the per-test resultstool/common_mark_stats.jsonand the test summarytool/common_mark_stats.txt. - Verify that more tests now pass – or at least, no more tests fail.
- Make sure you include the updated stats files in your commit.
Updating the CommonMark test file for a spec update
-
Check out the CommonMark source. Make sure you checkout a major release.
-
Dump the test output overwriting the existing tests file.
/path/to/common_mark_dir> python3 test/spec_tests.py --dump-tests \ > /path/to/markdown.dart/tool/common_mark_tests.json -
Update the stats files as described above. Note any changes in the results.
-
Update any references to the existing spec by search for
http://spec.commonmark.org/0.27in the repository. (Including this one.) Verify the updated links are still valid. -
Commit changes, including a corresponding note in
CHANGELOG.md.