OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 writeText() { | 98 writeText() { |
99 writeTextRange(start, pos); | 99 writeTextRange(start, pos); |
100 start = pos; | 100 start = pos; |
101 } | 101 } |
102 | 102 |
103 writeTextRange(int start, int end) { | 103 writeTextRange(int start, int end) { |
104 if (end > start) { | 104 if (end > start) { |
105 final text = source.substring(start, end); | 105 final text = source.substring(start, end); |
106 final nodes = _stack.last().children; | 106 final nodes = _stack.last.children; |
107 | 107 |
108 // If the previous node is text too, just append. | 108 // If the previous node is text too, just append. |
109 if ((nodes.length > 0) && (nodes.last() is Text)) { | 109 if ((nodes.length > 0) && (nodes.last is Text)) { |
110 final newNode = new Text('${nodes.last().text}$text'); | 110 final newNode = new Text('${nodes.last.text}$text'); |
111 nodes[nodes.length - 1] = newNode; | 111 nodes[nodes.length - 1] = newNode; |
112 } else { | 112 } else { |
113 nodes.add(new Text(text)); | 113 nodes.add(new Text(text)); |
114 } | 114 } |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 addNode(Node node) { | 118 addNode(Node node) { |
119 _stack.last().children.add(node); | 119 _stack.last.children.add(node); |
120 } | 120 } |
121 | 121 |
122 // TODO(rnystrom): Only need this because RegExp doesn't let you start | 122 // TODO(rnystrom): Only need this because RegExp doesn't let you start |
123 // searching from a given offset. | 123 // searching from a given offset. |
124 String get currentSource => source.substring(pos, source.length); | 124 String get currentSource => source.substring(pos, source.length); |
125 | 125 |
126 bool get isDone => pos == source.length; | 126 bool get isDone => pos == source.length; |
127 | 127 |
128 void advanceBy(int length) { | 128 void advanceBy(int length) { |
129 pos += length; | 129 pos += length; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 parser.consume(endMatch[0].length); | 387 parser.consume(endMatch[0].length); |
388 } else { | 388 } else { |
389 // Didn't close correctly so revert to text. | 389 // Didn't close correctly so revert to text. |
390 parser.start = startPos; | 390 parser.start = startPos; |
391 parser.advanceBy(endMatch[0].length); | 391 parser.advanceBy(endMatch[0].length); |
392 } | 392 } |
393 | 393 |
394 return null; | 394 return null; |
395 } | 395 } |
396 } | 396 } |
OLD | NEW |