| 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 // TODO(rnystrom): Use "package:" URL (#4968). | 8 // TODO(rnystrom): Use "package:" URL (#4968). |
| 9 #source('src/markdown/ast.dart'); | 9 #source('src/markdown/ast.dart'); |
| 10 #source('src/markdown/block_parser.dart'); | 10 #source('src/markdown/block_parser.dart'); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 final Map<String, Link> refLinks; | 39 final Map<String, Link> refLinks; |
| 40 | 40 |
| 41 Document() | 41 Document() |
| 42 : refLinks = <String, Link>{}; | 42 : refLinks = <String, Link>{}; |
| 43 | 43 |
| 44 parseRefLinks(List<String> lines) { | 44 parseRefLinks(List<String> lines) { |
| 45 // This is a hideous regex. It matches: | 45 // This is a hideous regex. It matches: |
| 46 // [id]: http:foo.com "some title" | 46 // [id]: http:foo.com "some title" |
| 47 // Where there may whitespace in there, and where the title may be in | 47 // Where there may whitespace in there, and where the title may be in |
| 48 // single quotes, double quotes, or parentheses. | 48 // single quotes, double quotes, or parentheses. |
| 49 final indent = @'^[ ]{0,3}'; // Leading indentation. | 49 final indent = r'^[ ]{0,3}'; // Leading indentation. |
| 50 final id = @'\[([^\]]+)\]'; // Reference id in [brackets]. | 50 final id = r'\[([^\]]+)\]'; // Reference id in [brackets]. |
| 51 final quote = @'"[^"]+"'; // Title in "double quotes". | 51 final quote = r'"[^"]+"'; // Title in "double quotes". |
| 52 final apos = @"'[^']+'"; // Title in 'single quotes'. | 52 final apos = r"'[^']+'"; // Title in 'single quotes'. |
| 53 final paren = @"\([^)]+\)"; // Title in (parentheses). | 53 final paren = r"\([^)]+\)"; // Title in (parentheses). |
| 54 final pattern = new RegExp( | 54 final pattern = new RegExp( |
| 55 '$indent$id:\\s+(\\S+)\\s*($quote|$apos|$paren|)\\s*\$'); | 55 '$indent$id:\\s+(\\S+)\\s*($quote|$apos|$paren|)\\s*\$'); |
| 56 | 56 |
| 57 for (int i = 0; i < lines.length; i++) { | 57 for (int i = 0; i < lines.length; i++) { |
| 58 final match = pattern.firstMatch(lines[i]); | 58 final match = pattern.firstMatch(lines[i]); |
| 59 if (match != null) { | 59 if (match != null) { |
| 60 // Parse the link. | 60 // Parse the link. |
| 61 var id = match[1]; | 61 var id = match[1]; |
| 62 var url = match[2]; | 62 var url = match[2]; |
| 63 var title = match[3]; | 63 var title = match[3]; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 /// `<em>this <strong>is</strong> a</em> <code>markdown</code>`. | 106 /// `<em>this <strong>is</strong> a</em> <code>markdown</code>`. |
| 107 List<Node> parseInline(String text) => new InlineParser(text, this).parse(); | 107 List<Node> parseInline(String text) => new InlineParser(text, this).parse(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 class Link { | 110 class Link { |
| 111 final String id; | 111 final String id; |
| 112 final String url; | 112 final String url; |
| 113 final String title; | 113 final String title; |
| 114 Link(this.id, this.url, this.title); | 114 Link(this.id, this.url, this.title); |
| 115 } | 115 } |
| OLD | NEW |