extension_set.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'block_parser.dart';
  2. import 'inline_parser.dart';
  3. /// ExtensionSets provide a simple grouping mechanism for common Markdown
  4. /// flavors.
  5. ///
  6. /// For example, the [gitHubFlavored] set of syntax extensions allows users to
  7. /// output HTML from their Markdown in a similar fashion to GitHub's parsing.
  8. class ExtensionSet {
  9. ExtensionSet(this.blockSyntaxes, this.inlineSyntaxes);
  10. /// The [ExtensionSet.none] extension set renders Markdown similar to
  11. /// [Markdown.pl].
  12. ///
  13. /// However, this set does not render _exactly_ the same as Markdown.pl;
  14. /// rather it is more-or-less the CommonMark standard of Markdown, without
  15. /// fenced code blocks, or inline HTML.
  16. ///
  17. /// [Markdown.pl]: http://daringfireball.net/projects/markdown/syntax
  18. static final ExtensionSet none = ExtensionSet([], []);
  19. /// The [commonMark] extension set is close to compliance with [CommonMark].
  20. ///
  21. /// [CommonMark]: http://commonmark.org/
  22. static final ExtensionSet commonMark =
  23. ExtensionSet([const FencedCodeBlockSyntax()], [InlineHtmlSyntax()]);
  24. /// The [gitHubWeb] extension set renders Markdown similarly to GitHub.
  25. ///
  26. /// This is different from the [gitHubFlavored] extension set in that GitHub
  27. /// actually renders HTML different from straight [GitHub flavored Markdown].
  28. ///
  29. /// (The only difference currently is that [gitHubWeb] renders headers with
  30. /// linkable IDs.)
  31. ///
  32. /// [GitHub flavored Markdown]: https://github.github.com/gfm/
  33. static final ExtensionSet gitHubWeb = ExtensionSet([
  34. const FencedCodeBlockSyntax(),
  35. const HeaderWithIdSyntax(),
  36. const SetextHeaderWithIdSyntax(),
  37. const TableSyntax()
  38. ], [
  39. InlineHtmlSyntax(),
  40. StrikethroughSyntax(),
  41. EmojiSyntax(),
  42. AutolinkExtensionSyntax(),
  43. ]);
  44. /// The [gitHubFlavored] extension set is close to compliance with the [GitHub
  45. /// flavored Markdown spec].
  46. ///
  47. /// [GitHub flavored Markdown]: https://github.github.com/gfm/
  48. static final ExtensionSet gitHubFlavored = ExtensionSet([
  49. const FencedCodeBlockSyntax(),
  50. const TableSyntax()
  51. ], [
  52. InlineHtmlSyntax(),
  53. StrikethroughSyntax(),
  54. AutolinkExtensionSyntax(),
  55. ]);
  56. final List<BlockSyntax> blockSyntaxes;
  57. final List<InlineSyntax> inlineSyntaxes;
  58. }