Make Syntax const
diff --git a/pkgs/markdown/lib/src/markdown/block_parser.dart b/pkgs/markdown/lib/src/markdown/block_parser.dart index d163e9c..a12033d 100644 --- a/pkgs/markdown/lib/src/markdown/block_parser.dart +++ b/pkgs/markdown/lib/src/markdown/block_parser.dart
@@ -88,28 +88,21 @@ abstract class BlockSyntax { /// Gets the collection of built-in block parsers. To turn a series of lines /// into blocks, each of these will be tried in turn. Order matters here. - static List<BlockSyntax> get syntaxes { - // Lazy initialize. - if (_syntaxes == null) { - _syntaxes = [ - new EmptyBlockSyntax(), - new BlockHtmlSyntax(), - new SetextHeaderSyntax(), - new HeaderSyntax(), - new CodeBlockSyntax(), - new FencedCodeBlockSyntax(), - new BlockquoteSyntax(), - new HorizontalRuleSyntax(), - new UnorderedListSyntax(), - new OrderedListSyntax(), - new ParagraphSyntax() - ]; - } + static const List<BlockSyntax> syntaxes = const[ + const EmptyBlockSyntax(), + const BlockHtmlSyntax(), + const SetextHeaderSyntax(), + const HeaderSyntax(), + const CodeBlockSyntax(), + const FencedCodeBlockSyntax(), + const BlockquoteSyntax(), + const HorizontalRuleSyntax(), + const UnorderedListSyntax(), + const OrderedListSyntax(), + const ParagraphSyntax() + ]; - return _syntaxes; - } - - static List<BlockSyntax> _syntaxes; + const BlockSyntax(); /// Gets the regex used to identify the beginning of this block, if any. RegExp get pattern => null; @@ -146,6 +139,8 @@ class EmptyBlockSyntax extends BlockSyntax { RegExp get pattern => _RE_EMPTY; + const EmptyBlockSyntax(); + Node parse(BlockParser parser) { parser.advance(); @@ -156,6 +151,9 @@ /// Parses setext-style headers. class SetextHeaderSyntax extends BlockSyntax { + + const SetextHeaderSyntax(); + bool canParse(BlockParser parser) { // Note: matches *next* line, not the current one. We're looking for the // underlining after this line. @@ -178,6 +176,8 @@ class HeaderSyntax extends BlockSyntax { RegExp get pattern => _RE_HEADER; + const HeaderSyntax(); + Node parse(BlockParser parser) { final match = pattern.firstMatch(parser.current); parser.advance(); @@ -191,6 +191,8 @@ class BlockquoteSyntax extends BlockSyntax { RegExp get pattern => _RE_BLOCKQUOTE; + const BlockquoteSyntax(); + Node parse(BlockParser parser) { final childLines = parseChildLines(parser); @@ -205,6 +207,8 @@ class CodeBlockSyntax extends BlockSyntax { RegExp get pattern => _RE_INDENT; + const CodeBlockSyntax(); + List<String> parseChildLines(BlockParser parser) { final childLines = <String>[]; @@ -249,7 +253,11 @@ class FencedCodeBlockSyntax extends BlockSyntax { RegExp get pattern => _RE_CODE; - List<String> parseChildLines(BlockParser parser, String endBlock) { + const FencedCodeBlockSyntax(); + + List<String> parseChildLines(BlockParser parser, [String endBlock]) { + if(endBlock == null) endBlock = ''; + final childLines = <String>[]; parser.advance(); while (!parser.isDone) { @@ -285,16 +293,14 @@ } return element; } - - void _addElementAttributes(Element element) { - - } } /// Parses horizontal rules like `---`, `_ _ _`, `* * *`, etc. class HorizontalRuleSyntax extends BlockSyntax { RegExp get pattern => _RE_HR; + const HorizontalRuleSyntax(); + Node parse(BlockParser parser) { final match = pattern.firstMatch(parser.current); parser.advance(); @@ -317,6 +323,8 @@ bool get canEndBlock => false; + const BlockHtmlSyntax(); + Node parse(BlockParser parser) { final childLines = []; @@ -343,6 +351,8 @@ String get listTag; + const ListSyntax(); + Node parse(BlockParser parser) { final items = <ListItem>[]; var childLines = <String>[]; @@ -485,18 +495,24 @@ class UnorderedListSyntax extends ListSyntax { RegExp get pattern => _RE_UL; String get listTag => 'ul'; + + const UnorderedListSyntax(); } /// Parses ordered lists. class OrderedListSyntax extends ListSyntax { RegExp get pattern => _RE_OL; String get listTag => 'ol'; + + const OrderedListSyntax(); } /// Parses paragraphs of regular text. class ParagraphSyntax extends BlockSyntax { bool get canEndBlock => false; + const ParagraphSyntax(); + bool canParse(BlockParser parser) => true; Node parse(BlockParser parser) {