| 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 /// Maintains the internal state needed to parse inline span elements in | 5 /// Maintains the internal state needed to parse inline span elements in |
| 6 /// markdown. | 6 /// markdown. |
| 7 class InlineParser { | 7 class InlineParser { |
| 8 static List<InlineSyntax> get syntaxes { | 8 static List<InlineSyntax> get syntaxes { |
| 9 // Lazy initialize. | 9 // Lazy initialize. |
| 10 if (_syntaxes == null) { | 10 if (_syntaxes == null) { |
| 11 _syntaxes = <InlineSyntax>[ | 11 _syntaxes = <InlineSyntax>[ |
| 12 // This first regexp matches plain text to accelerate parsing. It must |
| 13 // be written so that it does not match any prefix of any following |
| 14 // syntax. Most markdown is plain text, so it is faster to match one |
| 15 // regexp per 'word' rather than fail to match all the following regexps |
| 16 // at each non-syntax character position. It is much more important |
| 17 // that the regexp is fast than complete (for example, adding grouping |
| 18 // is likely to slow the regexp down enough to negate its benefit). |
| 19 // Since it is purely for optimization, it can be removed for debugging. |
| 20 new TextSyntax(r'\s*[A-Za-z0-9]+'), |
| 21 |
| 22 // The real syntaxes. |
| 23 |
| 12 new AutolinkSyntax(), | 24 new AutolinkSyntax(), |
| 13 new LinkSyntax(), | 25 new LinkSyntax(), |
| 14 // "*" surrounded by spaces is left alone. | 26 // "*" surrounded by spaces is left alone. |
| 15 new TextSyntax(r' \* '), | 27 new TextSyntax(r' \* '), |
| 16 // "_" surrounded by spaces is left alone. | 28 // "_" surrounded by spaces is left alone. |
| 17 new TextSyntax(r' _ '), | 29 new TextSyntax(r' _ '), |
| 18 // Leave already-encoded HTML entities alone. Ensures we don't turn | 30 // Leave already-encoded HTML entities alone. Ensures we don't turn |
| 19 // "&" into "&amp;" | 31 // "&" into "&amp;" |
| 20 new TextSyntax(r'&[#a-zA-Z0-9]*;'), | 32 new TextSyntax(r'&[#a-zA-Z0-9]*;'), |
| 21 // Encode "&". | 33 // Encode "&". |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 parser.consume(endMatch[0].length); | 399 parser.consume(endMatch[0].length); |
| 388 } else { | 400 } else { |
| 389 // Didn't close correctly so revert to text. | 401 // Didn't close correctly so revert to text. |
| 390 parser.start = startPos; | 402 parser.start = startPos; |
| 391 parser.advanceBy(endMatch[0].length); | 403 parser.advanceBy(endMatch[0].length); |
| 392 } | 404 } |
| 393 | 405 |
| 394 return null; | 406 return null; |
| 395 } | 407 } |
| 396 } | 408 } |
| OLD | NEW |