Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: third_party/pkg/markdown/lib/src/inline_parser.dart

Issue 220343004: Reverting 34583 - checked mode breaks (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/pkg.status ('k') | third_party/pkg/markdown/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library markdown.inline_parser; 5 library markdown.inline_parser;
6 6
7 import 'ast.dart'; 7 import 'ast.dart';
8 import 'document.dart'; 8 import 'document.dart';
9 import 'util.dart'; 9 import 'util.dart';
10 10
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // 1: Will be non-empty if it's either a ref or inline link. Will be empty 267 // 1: Will be non-empty if it's either a ref or inline link. Will be empty
268 // if it's just a bare pair of square brackets with nothing after them. 268 // if it's just a bare pair of square brackets with nothing after them.
269 // 2: Contains the id inside [] for a reference-style link. 269 // 2: Contains the id inside [] for a reference-style link.
270 // 3: Contains the URL for an inline link. 270 // 3: Contains the URL for an inline link.
271 // 4: Contains the title, if present, for an inline link. 271 // 4: Contains the title, if present, for an inline link.
272 } 272 }
273 273
274 LinkSyntax({this.linkResolver, String pattern: r'\['}) 274 LinkSyntax({this.linkResolver, String pattern: r'\['})
275 : super(pattern, end: linkPattern); 275 : super(pattern, end: linkPattern);
276 276
277 Element createNode(InlineParser parser, Match match, TagState state) { 277 Node createNode(InlineParser parser, Match match, TagState state) {
278 // If we didn't match refLink or inlineLink, then it means there was 278 // If we didn't match refLink or inlineLink, then it means there was
279 // nothing after the first square bracket, so it isn't a normal markdown 279 // nothing after the first square bracket, so it isn't a normal markdown
280 // link at all. Instead, we allow users of the library to specify a special 280 // link at all. Instead, we allow users of the library to specify a special
281 // resolver function ([linkResolver]) that may choose to handle 281 // resolver function ([linkResolver]) that may choose to handle
282 // this. Otherwise, it's just treated as plain text. 282 // this. Otherwise, it's just treated as plain text.
283 if (isNullOrEmpty(match[1])) { 283 if (isNullOrEmpty(match[1])) {
284 if (linkResolver == null) return null; 284 if (linkResolver == null) return null;
285 285
286 // Only allow implicit links if the content is just text. 286 // Only allow implicit links if the content is just text.
287 // TODO(rnystrom): Do we want to relax this? 287 // TODO(rnystrom): Do we want to relax this?
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 else 327 else
328 id = match[2]; 328 id = match[2];
329 329
330 // References are case-insensitive. 330 // References are case-insensitive.
331 id = id.toLowerCase(); 331 id = id.toLowerCase();
332 return parser.document.refLinks[id]; 332 return parser.document.refLinks[id];
333 } 333 }
334 } 334 }
335 335
336 bool onMatchEnd(InlineParser parser, Match match, TagState state) { 336 bool onMatchEnd(InlineParser parser, Match match, TagState state) {
337 Element node = createNode(parser, match, state); 337 Node node = createNode(parser, match, state);
338 if (node == null) return false; 338 if (node == null) return false;
339 parser.addNode(node); 339 parser.addNode(node);
340 return true; 340 return true;
341 } 341 }
342 } 342 }
343 343
344 /// Matches images like `![alternate text](url "optional title")` and 344 /// Matches images like `![alternate text](url "optional title")` and
345 /// `![alternate text][url reference]`. 345 /// `![alternate text][url reference]`.
346 class ImageLinkSyntax extends LinkSyntax { 346 class ImageLinkSyntax extends LinkSyntax {
347 Resolver linkResolver; 347 Resolver linkResolver;
348 ImageLinkSyntax({this.linkResolver}) 348 ImageLinkSyntax({this.linkResolver})
349 : super(pattern: r'!\['); 349 : super(pattern: r'!\[');
350 350
351 Element createNode(InlineParser parser, Match match, TagState state) { 351 Node createNode(InlineParser parser, Match match, TagState state) {
352 Element node = super.createNode(parser, match, state); 352 Node node = super.createNode(parser, match, state);
353 if (node == null) return null; 353 if (node == null) return null;
354 354
355 final Element imageElement = new Element.withTag("img") 355 final Element imageElement = new Element.withTag("img")
356 ..attributes["src"] = node.attributes["href"] 356 ..attributes["src"] = node.attributes["href"]
357 ..attributes["title"] = node.attributes["title"] 357 ..attributes["title"] = node.attributes["title"]
358 ..attributes["alt"] = node.children 358 ..attributes["alt"] = node.children
359 .map((e) => isNullOrEmpty(e) || e is! Text ? '' : e.text) 359 .map((e) => isNullOrEmpty(e) || e is! Text ? '' : e.text)
360 .join(' '); 360 .join(' ');
361 361
362 cleanMap(imageElement.attributes); 362 cleanMap(imageElement.attributes);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 parser.consume(endMatch[0].length); 447 parser.consume(endMatch[0].length);
448 } else { 448 } else {
449 // Didn't close correctly so revert to text. 449 // Didn't close correctly so revert to text.
450 parser.start = startPos; 450 parser.start = startPos;
451 parser.advanceBy(endMatch[0].length); 451 parser.advanceBy(endMatch[0].length);
452 } 452 }
453 453
454 return null; 454 return null;
455 } 455 }
456 } 456 }
OLDNEW
« no previous file with comments | « pkg/pkg.status ('k') | third_party/pkg/markdown/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698