| Index: lib/src/html_renderer.dart
|
| diff --git a/lib/src/html_renderer.dart b/lib/src/html_renderer.dart
|
| index 835c178075cf16c1cd1089d9821895589e52ff14..edb09a0b1825504d2ee5343fb738918a50dfba34 100644
|
| --- a/lib/src/html_renderer.dart
|
| +++ b/lib/src/html_renderer.dart
|
| @@ -2,38 +2,37 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -library markdown.html_renderer;
|
| +library markdown.src.html_renderer;
|
|
|
| import 'ast.dart';
|
| import 'document.dart';
|
| import 'inline_parser.dart';
|
|
|
| /// Converts the given string of markdown to HTML.
|
| -String markdownToHtml(String markdown, {List<InlineSyntax> inlineSyntaxes,
|
| - Resolver linkResolver, Resolver imageLinkResolver,
|
| +String markdownToHtml(String markdown,
|
| + {List<InlineSyntax> inlineSyntaxes,
|
| + Resolver linkResolver,
|
| + Resolver imageLinkResolver,
|
| bool inlineOnly: false}) {
|
| var document = new Document(
|
| inlineSyntaxes: inlineSyntaxes,
|
| imageLinkResolver: imageLinkResolver,
|
| linkResolver: linkResolver);
|
|
|
| - if (inlineOnly) {
|
| - return renderToHtml(document.parseInline(markdown));
|
| - } else {
|
| - // Replace windows line endings with unix line endings, and split.
|
| - var lines = markdown.replaceAll('\r\n', '\n').split('\n');
|
| - document.parseRefLinks(lines);
|
| - var blocks = document.parseLines(lines);
|
| - return renderToHtml(blocks);
|
| - }
|
| + if (inlineOnly) return renderToHtml(document.parseInline(markdown));
|
| +
|
| + // Replace windows line endings with unix line endings, and split.
|
| + var lines = markdown.replaceAll('\r\n', '\n').split('\n');
|
| + document.parseRefLinks(lines);
|
| +
|
| + return renderToHtml(document.parseLines(lines));
|
| }
|
|
|
| String renderToHtml(List<Node> nodes) => new HtmlRenderer().render(nodes);
|
|
|
| /// Translates a parsed AST to HTML.
|
| class HtmlRenderer implements NodeVisitor {
|
| - static final _BLOCK_TAGS = new RegExp(
|
| - 'blockquote|h1|h2|h3|h4|h5|h6|hr|p|pre');
|
| + static final _blockTags = new RegExp('blockquote|h1|h2|h3|h4|h5|h6|hr|p|pre');
|
|
|
| StringBuffer buffer;
|
|
|
| @@ -53,16 +52,17 @@ class HtmlRenderer implements NodeVisitor {
|
|
|
| bool visitElementBefore(Element element) {
|
| // Hackish. Separate block-level elements with newlines.
|
| - if (!buffer.isEmpty && _BLOCK_TAGS.firstMatch(element.tag) != null) {
|
| + if (!buffer.isEmpty && _blockTags.firstMatch(element.tag) != null) {
|
| buffer.write('\n');
|
| }
|
|
|
| buffer.write('<${element.tag}');
|
|
|
| // Sort the keys so that we generate stable output.
|
| - final attributeNames = element.attributes.keys.toList();
|
| + var attributeNames = element.attributes.keys.toList();
|
| attributeNames.sort((a, b) => a.compareTo(b));
|
| - for (final name in attributeNames) {
|
| +
|
| + for (var name in attributeNames) {
|
| buffer.write(' $name="${element.attributes[name]}"');
|
| }
|
|
|
|
|