| 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 Node setImplicitLinkResolver(Node resolver(String text)) { | 32 Node setImplicitLinkResolver(Node resolver(String text)) { |
| 33 _implicitLinkResolver = resolver; | 33 _implicitLinkResolver = resolver; |
| 34 } | 34 } |
| 35 | 35 |
| 36 /// Maintains the context needed to parse a markdown document. | 36 /// Maintains the context needed to parse a markdown document. |
| 37 class Document { | 37 class Document { |
| 38 final Map<String, Link> refLinks; | 38 final Map<String, Link> refLinks; |
| 39 | 39 |
| 40 Document() | 40 Document() |
| 41 : refLinks = <Link>{}; | 41 : refLinks = <String, Link>{}; |
| 42 | 42 |
| 43 parseRefLinks(List<String> lines) { | 43 parseRefLinks(List<String> lines) { |
| 44 // This is a hideous regex. It matches: | 44 // This is a hideous regex. It matches: |
| 45 // [id]: http:foo.com "some title" | 45 // [id]: http:foo.com "some title" |
| 46 // Where there may whitespace in there, and where the title may be in | 46 // Where there may whitespace in there, and where the title may be in |
| 47 // single quotes, double quotes, or parentheses. | 47 // single quotes, double quotes, or parentheses. |
| 48 final indent = @'^[ ]{0,3}'; // Leading indentation. | 48 final indent = @'^[ ]{0,3}'; // Leading indentation. |
| 49 final id = @'\[([^\]]+)\]'; // Reference id in [brackets]. | 49 final id = @'\[([^\]]+)\]'; // Reference id in [brackets]. |
| 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'. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 /// `<em>this <strong>is</strong> a</em> <code>markdown</code>`. | 105 /// `<em>this <strong>is</strong> a</em> <code>markdown</code>`. |
| 106 List<Node> parseInline(String text) => new InlineParser(text, this).parse(); | 106 List<Node> parseInline(String text) => new InlineParser(text, this).parse(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 class Link { | 109 class Link { |
| 110 final String id; | 110 final String id; |
| 111 final String url; | 111 final String url; |
| 112 final String title; | 112 final String title; |
| 113 Link(this.id, this.url, this.title); | 113 Link(this.id, this.url, this.title); |
| 114 } | 114 } |
| OLD | NEW |