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

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

Issue 189333002: pkg/docgen: update markdown to 0.5.1 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updates Created 6 years, 9 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 library markdown.document;
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.
4 2
5 /// Parses text in a markdown-like format and renders to HTML. 3 import 'ast.dart';
6 library markdown; 4 import 'block_parser.dart';
7 5 import 'inline_parser.dart';
8 // TODO(rnystrom): Use "package:" URL (#4968).
9 part 'src/markdown/ast.dart';
10 part 'src/markdown/block_parser.dart';
11 part 'src/markdown/html_renderer.dart';
12 part 'src/markdown/inline_parser.dart';
13
14 typedef Node Resolver(String name);
15
16 /// Converts the given string of markdown to HTML.
17 String markdownToHtml(String markdown, {inlineSyntaxes, linkResolver}) {
18 final document = new Document(inlineSyntaxes: inlineSyntaxes,
19 linkResolver: linkResolver);
20
21 // Replace windows line endings with unix line endings, and split.
22 final lines = markdown.replaceAll('\r\n','\n').split('\n');
23 document.parseRefLinks(lines);
24 final blocks = document.parseLines(lines);
25 return renderToHtml(blocks);
26 }
27
28 /// Replaces `<`, `&`, and `>`, with their HTML entity equivalents.
29 String escapeHtml(String html) {
30 return html.replaceAll('&', '&amp;')
31 .replaceAll('<', '&lt;')
32 .replaceAll('>', '&gt;');
33 }
34 6
35 /// Maintains the context needed to parse a markdown document. 7 /// Maintains the context needed to parse a markdown document.
36 class Document { 8 class Document {
37 final Map<String, Link> refLinks; 9 final Map<String, Link> refLinks;
38 List<InlineSyntax> inlineSyntaxes; 10 List<InlineSyntax> inlineSyntaxes;
39 Resolver linkResolver; 11 Resolver linkResolver;
40 12
41 Document({this.inlineSyntaxes, this.linkResolver}) 13 Document({this.inlineSyntaxes, this.linkResolver})
42 : refLinks = <String, Link>{}; 14 : refLinks = <String, Link>{};
43 15
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 /// `<em>this <strong>is</strong> a</em> <code>markdown</code>`. 78 /// `<em>this <strong>is</strong> a</em> <code>markdown</code>`.
107 List<Node> parseInline(String text) => new InlineParser(text, this).parse(); 79 List<Node> parseInline(String text) => new InlineParser(text, this).parse();
108 } 80 }
109 81
110 class Link { 82 class Link {
111 final String id; 83 final String id;
112 final String url; 84 final String url;
113 final String title; 85 final String title;
114 Link(this.id, this.url, this.title); 86 Link(this.id, this.url, this.title);
115 } 87 }
OLDNEW
« no previous file with comments | « third_party/pkg/markdown/lib/src/block_parser.dart ('k') | third_party/pkg/markdown/lib/src/html_renderer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698