OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of markdown; | 5 part of markdown; |
6 | 6 |
7 /// The line contains only whitespace or is empty. | 7 /// The line contains only whitespace or is empty. |
8 final _RE_EMPTY = new RegExp(r'^([ \t]*)$'); | 8 final _RE_EMPTY = new RegExp(r'^([ \t]*)$'); |
9 | 9 |
10 /// A series of `=` or `-` (on the next line) define setext-style headers. | 10 /// A series of `=` or `-` (on the next line) define setext-style headers. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 childLines.add(match[1]); | 128 childLines.add(match[1]); |
129 parser.advance(); | 129 parser.advance(); |
130 } | 130 } |
131 | 131 |
132 return childLines; | 132 return childLines; |
133 } | 133 } |
134 | 134 |
135 /// Gets whether or not [parser]'s current line should end the previous block. | 135 /// Gets whether or not [parser]'s current line should end the previous block. |
136 static bool isAtBlockEnd(BlockParser parser) { | 136 static bool isAtBlockEnd(BlockParser parser) { |
137 if (parser.isDone) return true; | 137 if (parser.isDone) return true; |
138 return syntaxes.some((s) => s.canParse(parser) && s.canEndBlock); | 138 return syntaxes.any((s) => s.canParse(parser) && s.canEndBlock); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 class EmptyBlockSyntax extends BlockSyntax { | 142 class EmptyBlockSyntax extends BlockSyntax { |
143 RegExp get pattern => _RE_EMPTY; | 143 RegExp get pattern => _RE_EMPTY; |
144 | 144 |
145 Node parse(BlockParser parser) { | 145 Node parse(BlockParser parser) { |
146 parser.advance(); | 146 parser.advance(); |
147 | 147 |
148 // Don't actually emit anything. | 148 // Don't actually emit anything. |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 while (!BlockSyntax.isAtBlockEnd(parser)) { | 455 while (!BlockSyntax.isAtBlockEnd(parser)) { |
456 childLines.add(parser.current); | 456 childLines.add(parser.current); |
457 parser.advance(); | 457 parser.advance(); |
458 } | 458 } |
459 | 459 |
460 final contents = parser.document.parseInline( | 460 final contents = parser.document.parseInline( |
461 Strings.join(childLines, '\n')); | 461 Strings.join(childLines, '\n')); |
462 return new Element('p', contents); | 462 return new Element('p', contents); |
463 } | 463 } |
464 } | 464 } |
OLD | NEW |