Add support for GFM's strikethrough syntax (dart-lang/markdown#199) Add support for GFM's strikethrough syntax
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index 306b2b1..dc28e7a 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md
@@ -3,6 +3,8 @@ * Overhaul support for emphasis (`*foo*` and `_foo_`) and strong emphasis (`**foo**` and `__foo__`), dramatically improving CommonMark compliance. * Improve support for tab characters, and horizontal rules. +* Add support for GitHub Flavored Markdown's Strikethrough extension. See the + [GFM spec][strikethrough]. * The above fixes raise compliance with the CommonMark specs to 90%, and compliance with the GFM specs to 87%. * Allow the binary script to take a `--extension-set` option. @@ -14,6 +16,7 @@ $ markdown ``` +[strikethrough]: https://github.github.com/gfm/#strikethrough-extension- [pub-global]: https://www.dartlang.org/tools/pub/cmd/pub-global#running-a-script-from-your-path ## 1.1.1
diff --git a/pkgs/markdown/README.md b/pkgs/markdown/README.md index 5fbe97c..fd1e11e 100644 --- a/pkgs/markdown/README.md +++ b/pkgs/markdown/README.md
@@ -69,7 +69,7 @@ * `new InlineHtmlSyntax()` * `const FencedCodeBlockSyntax()` -* `ExtensionSet.gitHubWeb` includes six extensions: +* `ExtensionSet.gitHubWeb` includes seven extensions: * `new EmojiSyntax()` * `new InlineHtmlSyntax()` @@ -78,6 +78,7 @@ * `const SetextHeaderWithIdSyntax()`, which adds `id` attributes to Setext-style headers, for easy intra-document linking. * `const FencedCodeBlockSyntax()` + * `new StrikethroughSyntax()` * `const TableSyntax()` ### Custom syntax extensions
diff --git a/pkgs/markdown/lib/src/extension_set.dart b/pkgs/markdown/lib/src/extension_set.dart index 984ca6e..bab57e5 100644 --- a/pkgs/markdown/lib/src/extension_set.dart +++ b/pkgs/markdown/lib/src/extension_set.dart
@@ -38,6 +38,7 @@ const TableSyntax() ], [ new InlineHtmlSyntax(), + new StrikethroughSyntax(), new EmojiSyntax(), ]); @@ -45,9 +46,13 @@ /// flavored Markdown spec]. /// /// [GitHub flavored Markdown]: https://github.github.com/gfm/ - static final ExtensionSet gitHubFlavored = new ExtensionSet( - [const FencedCodeBlockSyntax(), const TableSyntax()], - [new InlineHtmlSyntax()]); + static final ExtensionSet gitHubFlavored = new ExtensionSet([ + const FencedCodeBlockSyntax(), + const TableSyntax() + ], [ + new InlineHtmlSyntax(), + new StrikethroughSyntax(), + ]); /// The deprecated name for the [gitHubFlavored] extension set. @deprecated
diff --git a/pkgs/markdown/lib/src/inline_parser.dart b/pkgs/markdown/lib/src/inline_parser.dart index fb6e8df..060d696 100644 --- a/pkgs/markdown/lib/src/inline_parser.dart +++ b/pkgs/markdown/lib/src/inline_parser.dart
@@ -430,6 +430,25 @@ } } +/// Matches strikethrough syntax according to the GFM spec. +class StrikethroughSyntax extends TagSyntax { + StrikethroughSyntax() : super('~+', requiresDelimiterRun: true); + + @override + bool onMatchEnd(InlineParser parser, Match match, TagState state) { + var runLength = match.group(0).length; + var matchStart = parser.pos; + var matchEnd = parser.pos + runLength - 1; + var delimiterRun = _DelimiterRun.tryParse(parser, matchStart, matchEnd); + if (!delimiterRun.isRightFlanking) { + return false; + } + + parser.addNode(new Element('del', state.children)); + return true; + } +} + /// Matches inline links like `[blah][id]` and `[blah](url)`. class LinkSyntax extends TagSyntax { final Resolver linkResolver;
diff --git a/pkgs/markdown/pubspec.yaml b/pkgs/markdown/pubspec.yaml index 031b66a..25fa227 100644 --- a/pkgs/markdown/pubspec.yaml +++ b/pkgs/markdown/pubspec.yaml
@@ -9,11 +9,11 @@ environment: sdk: '>=1.12.0 <2.0.0' + dependencies: args: '^1.0.0' dev_dependencies: - args: '^1.0.0' # Only for example/app.dart. browser: any collection: '^1.2.0'
diff --git a/pkgs/markdown/tool/gfm_stats.json b/pkgs/markdown/tool/gfm_stats.json index 5e0b8bb..ffa7b1c 100644 --- a/pkgs/markdown/tool/gfm_stats.json +++ b/pkgs/markdown/tool/gfm_stats.json
@@ -653,8 +653,8 @@ "646": "loose" }, "Strikethrough (extension)": { - "469": "fail", - "470": "fail", + "469": "strict", + "470": "strict", "471": "strict" }, "Tables (extension)": {
diff --git a/pkgs/markdown/tool/gfm_stats.txt b/pkgs/markdown/tool/gfm_stats.txt index 656284c..0c472ca 100644 --- a/pkgs/markdown/tool/gfm_stats.txt +++ b/pkgs/markdown/tool/gfm_stats.txt
@@ -23,9 +23,9 @@ 15 of 21 – 71.4% Raw HTML 25 of 26 – 96.2% Setext headings 2 of 2 – 100.0% Soft line breaks - 1 of 3 – 33.3% Strikethrough (extension) + 3 of 3 – 100.0% Strikethrough (extension) 2 of 8 – 25.0% Tables (extension) 11 of 11 – 100.0% Tabs 3 of 3 – 100.0% Textual content 19 of 19 – 100.0% Thematic breaks - 564 of 647 – 87.2% TOTAL + 566 of 647 – 87.5% TOTAL