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 /// The line contains only whitespace or is empty. | 5 /// The line contains only whitespace or is empty. |
6 final _RE_EMPTY = const RegExp(@'^([ \t]*)$'); | 6 final _RE_EMPTY = const RegExp(@'^([ \t]*)$'); |
7 | 7 |
8 /// A series of `=` or `-` (on the next line) define setext-style headers. | 8 /// A series of `=` or `-` (on the next line) define setext-style headers. |
9 final _RE_SETEXT = const RegExp(@'^((=+)|(-+))$'); | 9 final _RE_SETEXT = const RegExp(@'^((=+)|(-+))$'); |
10 | 10 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 if (tryMatch(_RE_EMPTY)) { | 286 if (tryMatch(_RE_EMPTY)) { |
287 // Add a blank line to the current list item. | 287 // Add a blank line to the current list item. |
288 childLines.add(''); | 288 childLines.add(''); |
289 } else if (tryMatch(_RE_UL) || tryMatch(_RE_OL)) { | 289 } else if (tryMatch(_RE_UL) || tryMatch(_RE_OL)) { |
290 // End the current list item and start a new one. | 290 // End the current list item and start a new one. |
291 endItem(); | 291 endItem(); |
292 childLines.add(match[1]); | 292 childLines.add(match[1]); |
293 } else if (tryMatch(_RE_INDENT)) { | 293 } else if (tryMatch(_RE_INDENT)) { |
294 // Strip off indent and add to current item. | 294 // Strip off indent and add to current item. |
295 childLines.add(match[1]); | 295 childLines.add(match[1]); |
296 } else if (isAtBlockEnd(parser)) { | 296 } else if (BlockSyntax.isAtBlockEnd(parser)) { |
297 // Done with the list. | 297 // Done with the list. |
298 break; | 298 break; |
299 } else { | 299 } else { |
300 // Anything else is paragraph text or other stuff that can be in a list | 300 // Anything else is paragraph text or other stuff that can be in a list |
301 // item. However, if the previous item is a blank line, this means we're | 301 // item. However, if the previous item is a blank line, this means we're |
302 // done with the list and are starting a new top-level paragraph. | 302 // done with the list and are starting a new top-level paragraph. |
303 if ((childLines.length > 0) && (childLines.last() == '')) break; | 303 if ((childLines.length > 0) && (childLines.last() == '')) break; |
304 childLines.add(parser.current); | 304 childLines.add(parser.current); |
305 } | 305 } |
306 parser.advance(); | 306 parser.advance(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 /// Parses paragraphs of regular text. | 417 /// Parses paragraphs of regular text. |
418 class ParagraphSyntax extends BlockSyntax { | 418 class ParagraphSyntax extends BlockSyntax { |
419 bool get canEndBlock() => false; | 419 bool get canEndBlock() => false; |
420 | 420 |
421 bool canParse(BlockParser parser) => true; | 421 bool canParse(BlockParser parser) => true; |
422 | 422 |
423 Node parse(BlockParser parser) { | 423 Node parse(BlockParser parser) { |
424 final childLines = []; | 424 final childLines = []; |
425 | 425 |
426 // Eat until we hit something that ends a paragraph. | 426 // Eat until we hit something that ends a paragraph. |
427 while (!isAtBlockEnd(parser)) { | 427 while (!BlockSyntax.isAtBlockEnd(parser)) { |
428 childLines.add(parser.current); | 428 childLines.add(parser.current); |
429 parser.advance(); | 429 parser.advance(); |
430 } | 430 } |
431 | 431 |
432 final contents = parser.document.parseInline( | 432 final contents = parser.document.parseInline( |
433 Strings.join(childLines, '\n')); | 433 Strings.join(childLines, '\n')); |
434 return new Element('p', contents); | 434 return new Element('p', contents); |
435 } | 435 } |
436 } | 436 } |
OLD | NEW |