| 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) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 167 } |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 | 170 |
| 171 abstract bool onMatch(InlineParser parser, Match match); | 171 abstract bool onMatch(InlineParser parser, Match match); |
| 172 } | 172 } |
| 173 | 173 |
| 174 /// Matches stuff that should just be passed through as straight text. | 174 /// Matches stuff that should just be passed through as straight text. |
| 175 class TextSyntax extends InlineSyntax { | 175 class TextSyntax extends InlineSyntax { |
| 176 String substitute; | 176 String substitute; |
| 177 TextSyntax(String pattern, [String sub]) | 177 TextSyntax(String pattern, {String sub}) |
| 178 : super(pattern), | 178 : super(pattern), |
| 179 substitute = sub; | 179 substitute = sub; |
| 180 | 180 |
| 181 bool onMatch(InlineParser parser, Match match) { | 181 bool onMatch(InlineParser parser, Match match) { |
| 182 if (substitute == null) { | 182 if (substitute == null) { |
| 183 // Just use the original matched text. | 183 // Just use the original matched text. |
| 184 parser.advanceBy(match[0].length); | 184 parser.advanceBy(match[0].length); |
| 185 return false; | 185 return false; |
| 186 } | 186 } |
| 187 | 187 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 207 return true; | 207 return true; |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 /// Matches syntax that has a pair of tags and becomes an element, like `*` for | 211 /// Matches syntax that has a pair of tags and becomes an element, like `*` for |
| 212 /// `<em>`. Allows nested tags. | 212 /// `<em>`. Allows nested tags. |
| 213 class TagSyntax extends InlineSyntax { | 213 class TagSyntax extends InlineSyntax { |
| 214 final RegExp endPattern; | 214 final RegExp endPattern; |
| 215 final String tag; | 215 final String tag; |
| 216 | 216 |
| 217 TagSyntax(String pattern, [String tag, String end = null]) | 217 TagSyntax(String pattern, {String tag, String end}) |
| 218 : super(pattern), | 218 : super(pattern), |
| 219 endPattern = new RegExp((end != null) ? end : pattern, multiLine: true), | 219 endPattern = new RegExp((end != null) ? end : pattern, multiLine: true), |
| 220 tag = tag; | 220 tag = tag; |
| 221 // TODO(rnystrom): Doing this.field doesn't seem to work with named args. | 221 // TODO(rnystrom): Doing this.field doesn't seem to work with named args. |
| 222 | 222 |
| 223 bool onMatch(InlineParser parser, Match match) { | 223 bool onMatch(InlineParser parser, Match match) { |
| 224 parser._stack.add(new TagState(parser.pos, | 224 parser._stack.add(new TagState(parser.pos, |
| 225 parser.pos + match[0].length, this)); | 225 parser.pos + match[0].length, this)); |
| 226 return true; | 226 return true; |
| 227 } | 227 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 parser.consume(endMatch[0].length); | 399 parser.consume(endMatch[0].length); |
| 400 } else { | 400 } else { |
| 401 // Didn't close correctly so revert to text. | 401 // Didn't close correctly so revert to text. |
| 402 parser.start = startPos; | 402 parser.start = startPos; |
| 403 parser.advanceBy(endMatch[0].length); | 403 parser.advanceBy(endMatch[0].length); |
| 404 } | 404 } |
| 405 | 405 |
| 406 return null; | 406 return null; |
| 407 } | 407 } |
| 408 } | 408 } |
| OLD | NEW |