Merge pull request dart-lang/markdown#87 from mehaase/linebreaks
Fixes dart-lang/markdowndart-lang/markdown#86.
diff --git a/pkgs/markdown/lib/src/html_renderer.dart b/pkgs/markdown/lib/src/html_renderer.dart
index 184f9f9..03977ca 100644
--- a/pkgs/markdown/lib/src/html_renderer.dart
+++ b/pkgs/markdown/lib/src/html_renderer.dart
@@ -85,6 +85,11 @@
if (element.isEmpty) {
// Empty element like <hr/>.
buffer.write(' />');
+
+ if (element.tag == 'br') {
+ buffer.write('\n');
+ }
+
return false;
} else {
buffer.write('>');
diff --git a/pkgs/markdown/lib/src/inline_parser.dart b/pkgs/markdown/lib/src/inline_parser.dart
index 9be8704..6a70cc1 100644
--- a/pkgs/markdown/lib/src/inline_parser.dart
+++ b/pkgs/markdown/lib/src/inline_parser.dart
@@ -14,6 +14,7 @@
static final List<InlineSyntax> _defaultSyntaxes =
new List<InlineSyntax>.unmodifiable(<InlineSyntax>[
new AutolinkSyntax(),
+ new LineBreakSyntax(),
new LinkSyntax(),
new ImageSyntax(),
// Allow any punctuation to be escaped.
@@ -29,10 +30,6 @@
new TextSyntax(r'&', sub: '&'),
// Encode "<". (Why not encode ">" too? Gruber is toying with us.)
new TextSyntax(r'<', sub: '<'),
- // Escaped newlines become hard line breaks.
- new TextSyntax(r'\\\n', sub: '<br />\n'),
- // Two or more spaces at the end of a line become hard line breaks.
- new TextSyntax(r' +\n', sub: '<br />\n'),
// Parse "**strong**" tags.
new TagSyntax(r'\*\*', tag: 'strong'),
// Parse "__strong__" tags.
@@ -191,6 +188,17 @@
bool onMatch(InlineParser parser, Match match);
}
+/// Represents a hard line break.
+class LineBreakSyntax extends InlineSyntax {
+ LineBreakSyntax() : super(r'(?:\\| +)\n');
+
+ /// Create a void <br> element.
+ bool onMatch(InlineParser parser, Match match) {
+ parser.addNode(new Element.empty('br'));
+ return true;
+ }
+}
+
/// Matches stuff that should just be passed through as straight text.
class TextSyntax extends InlineSyntax {
final String substitute;