| 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 /// Parses text in a markdown-like format and renders to HTML. | 5 /// Parses text in a markdown-like format and renders to HTML. |
| 6 #library('markdown'); | 6 #library('markdown'); |
| 7 | 7 |
| 8 #source('ast.dart'); | 8 #source('ast.dart'); |
| 9 #source('block_parser.dart'); | 9 #source('block_parser.dart'); |
| 10 #source('html_renderer.dart'); | 10 #source('html_renderer.dart'); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 final quote = @'"[^"]+"'; // Title in "double quotes". | 50 final quote = @'"[^"]+"'; // Title in "double quotes". |
| 51 final apos = @"'[^']+'"; // Title in 'single quotes'. | 51 final apos = @"'[^']+'"; // Title in 'single quotes'. |
| 52 final paren = @"\([^)]+\)"; // Title in (parentheses). | 52 final paren = @"\([^)]+\)"; // Title in (parentheses). |
| 53 final pattern = new RegExp( | 53 final pattern = new RegExp( |
| 54 '$indent$id:\\s+(\\S+)\\s*($quote|$apos|$paren|)\\s*\$'); | 54 '$indent$id:\\s+(\\S+)\\s*($quote|$apos|$paren|)\\s*\$'); |
| 55 | 55 |
| 56 for (int i = 0; i < lines.length; i++) { | 56 for (int i = 0; i < lines.length; i++) { |
| 57 final match = pattern.firstMatch(lines[i]); | 57 final match = pattern.firstMatch(lines[i]); |
| 58 if (match != null) { | 58 if (match != null) { |
| 59 // Parse the link. | 59 // Parse the link. |
| 60 final id = match[1]; | 60 var id = match[1]; |
| 61 final url = match[2]; | 61 var url = match[2]; |
| 62 var title = match[3]; | 62 var title = match[3]; |
| 63 | 63 |
| 64 if (title == '') { | 64 if (title == '') { |
| 65 // No title. | 65 // No title. |
| 66 title = null; | 66 title = null; |
| 67 } else { | 67 } else { |
| 68 // Remove "", '', or (). | 68 // Remove "", '', or (). |
| 69 title = title.substring(1, title.length - 1); | 69 title = title.substring(1, title.length - 1); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // References are case-insensitive. |
| 73 id = id.toLowerCase(); |
| 74 |
| 72 refLinks[id] = new Link(id, url, title); | 75 refLinks[id] = new Link(id, url, title); |
| 73 | 76 |
| 74 // Remove it from the output. We replace it with a blank line which will | 77 // Remove it from the output. We replace it with a blank line which will |
| 75 // get consumed by later processing. | 78 // get consumed by later processing. |
| 76 lines[i] = ''; | 79 lines[i] = ''; |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 | 83 |
| 81 /// Parse the given [lines] of markdown to a series of AST nodes. | 84 /// Parse the given [lines] of markdown to a series of AST nodes. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 102 /// `<em>this <strong>is</strong> a</em> <code>markdown</code>`. | 105 /// `<em>this <strong>is</strong> a</em> <code>markdown</code>`. |
| 103 List<Node> parseInline(String text) => new InlineParser(text, this).parse(); | 106 List<Node> parseInline(String text) => new InlineParser(text, this).parse(); |
| 104 } | 107 } |
| 105 | 108 |
| 106 class Link { | 109 class Link { |
| 107 final String id; | 110 final String id; |
| 108 final String url; | 111 final String url; |
| 109 final String title; | 112 final String title; |
| 110 Link(this.id, this.url, this.title); | 113 Link(this.id, this.url, this.title); |
| 111 } | 114 } |
| OLD | NEW |