markdown
markdown copied to clipboard
<br/> to <br/> is bug?
String data = "Hello ABC, <br/> I would like to thank you...."
print(markdownToHtml(data));
The output is <p>Hello ABC, <br/> I would like to thank you....</p>
if use <br />
instead of <br/>
, result is <p>Hello ABC, <br /> I would like to thank you....</p>
Originally posted by @KagurazakaHanabi in https://github.com/flutter/flutter_markdown/issues/141#issuecomment-549797734
I believe this is a bug. The CommonMark spec for open tags and empty elements allows this.
The cause of this problem is the InlineHtmlSyntax that requires a space before the closing bracket.
class InlineHtmlSyntax extends TextSyntax {
InlineHtmlSyntax()
: super(r'<[/!?]?[A-Za-z][A-Za-z0-9-]*(?:\s[^>]*)?>',
startCharacter: $lt);
}
You could possibly use this to also allow the self-closing element
<[/!?]?[A-Za-z][A-Za-z0-9-]*(?:\s[^>]*|[/>]*)?>
Note that you can add your own inline syntaxes to get around this problem:
import 'package:charcode/charcode.dart';
import 'package:markdown/markdown.dart' as md;
class ImprovedInlineHtmlSyntax extends md.TextSyntax {
ImprovedInlineHtmlSyntax()
: super(r'<[/!?]?[A-Za-z][A-Za-z0-9-]*(?:\s[^>]*|[/>]*)?>', startCharacter: $lt);
}
md.markdownToHtml(notes,
extensionSet: md.ExtensionSet.gitHubWeb, inlineSyntaxes: [ImprovedInlineHtmlSyntax()]);