Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Add a new syntax `BlockHtmlSyntax` to parse HTML blocks.
* Add a new syntax `DecodeHtmlSyntax` to decode HTML entity and numeric
character references.
* Add a new syntax `SoftLineBreakSyntax` to remove the single space before the
line ending.
* Deprecate `BlockTagBlockHtmlSyntax`, `LongBlockHtmlSyntax` and
`OtherTagBlockHtmlSyntax`. These syntaxes will be removed from the next major
version.
Expand Down
1 change: 1 addition & 0 deletions lib/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export 'src/inline_syntaxes/inline_html_syntax.dart';
export 'src/inline_syntaxes/inline_syntax.dart';
export 'src/inline_syntaxes/line_break_syntax.dart';
export 'src/inline_syntaxes/link_syntax.dart';
export 'src/inline_syntaxes/soft_line_break_syntax.dart';
export 'src/inline_syntaxes/strikethrough_syntax.dart';
export 'src/inline_syntaxes/tag_syntax.dart';
export 'src/inline_syntaxes/text_syntax.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/src/inline_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'inline_syntaxes/image_syntax.dart';
import 'inline_syntaxes/inline_syntax.dart';
import 'inline_syntaxes/line_break_syntax.dart';
import 'inline_syntaxes/link_syntax.dart';
import 'inline_syntaxes/soft_line_break_syntax.dart';
import 'inline_syntaxes/text_syntax.dart';

/// Maintains the internal state needed to parse inline span elements in
Expand All @@ -37,6 +38,7 @@ class InlineParser {
// Parse "__strong__" and "_emphasis_" tags.
EmphasisSyntax.underscore(),
CodeSyntax(),
SoftLineBreakSyntax(),
// We will add the LinkSyntax once we know about the specific link resolver.
]);

Expand Down
21 changes: 21 additions & 0 deletions lib/src/inline_syntaxes/soft_line_break_syntax.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// 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.

import '../charcode.dart';
import '../inline_parser.dart';
import 'inline_syntax.dart';

/// Removes the single space before the line ending.
// https://spec.commonmark.org/0.30/#soft-line-breaks.
// If there are more than one spaces before the line ending, it may hit the hard
// break syntax.
class SoftLineBreakSyntax extends InlineSyntax {
SoftLineBreakSyntax() : super(' \n', startCharacter: $space);

@override
bool onMatch(InlineParser parser, Match match) {
parser.consume(1);
return false;
}
}
2 changes: 1 addition & 1 deletion test/common_mark/images.unit
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ My ![foo bar](/path/to/train.jpg "title" )

[foo]: /url "title"
<<<
<p><img src="/url" alt="foo" title="title" />
<p><img src="/url" alt="foo" title="title" />
[]</p>
>>> Images - 587
![foo]
Expand Down
2 changes: 1 addition & 1 deletion test/common_mark/links.unit
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ bar>)</p>

[foo]: /url "title"
<<<
<p><a href="/url" title="title">foo</a>
<p><a href="/url" title="title">foo</a>
[]</p>
>>> Links - 556
[foo]
Expand Down
2 changes: 1 addition & 1 deletion test/common_mark/soft_line_breaks.unit
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ baz</p>
foo
baz
<<<
<p>foo
<p>foo
baz</p>
2 changes: 1 addition & 1 deletion test/gfm/images.unit
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ My ![foo bar](/path/to/train.jpg "title" )

[foo]: /url "title"
<<<
<p><img src="/url" alt="foo" title="title" />
<p><img src="/url" alt="foo" title="title" />
[]</p>
>>> Images - 596
![foo]
Expand Down
2 changes: 1 addition & 1 deletion test/gfm/links.unit
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ bar>)</p>

[foo]: /url "title"
<<<
<p><a href="/url" title="title">foo</a>
<p><a href="/url" title="title">foo</a>
[]</p>
>>> Links - 565
[foo]
Expand Down
2 changes: 1 addition & 1 deletion test/gfm/soft_line_breaks.unit
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ baz</p>
foo
baz
<<<
<p>foo
<p>foo
baz</p>
6 changes: 3 additions & 3 deletions tool/common_mark_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@
"583": "strict",
"584": "strict",
"585": "strict",
"586": "loose",
"586": "strict",
"587": "strict",
"588": "strict",
"589": "loose",
Expand Down Expand Up @@ -500,7 +500,7 @@
"552": "strict",
"553": "strict",
"554": "strict",
"555": "loose",
"555": "strict",
"556": "strict",
"557": "strict",
"558": "strict",
Expand Down Expand Up @@ -662,7 +662,7 @@
},
"Soft line breaks": {
"648": "strict",
"649": "loose"
"649": "strict"
},
"Tabs": {
"1": "strict",
Expand Down
2 changes: 1 addition & 1 deletion tool/common_mark_stats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
622 of 652 – 95.4% TOTAL
559 of 622 – 89.9% TOTAL Strict
562 of 622 – 90.4% TOTAL Strict
6 changes: 3 additions & 3 deletions tool/gfm_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
"592": "strict",
"593": "strict",
"594": "strict",
"595": "loose",
"595": "strict",
"596": "strict",
"597": "strict",
"598": "loose",
Expand Down Expand Up @@ -513,7 +513,7 @@
"561": "strict",
"562": "strict",
"563": "strict",
"564": "loose",
"564": "strict",
"565": "strict",
"566": "strict",
"567": "strict",
Expand Down Expand Up @@ -675,7 +675,7 @@
},
"Soft line breaks": {
"669": "strict",
"670": "loose"
"670": "strict"
},
"Strikethrough (extension)": {
"491": "strict",
Expand Down
2 changes: 1 addition & 1 deletion tool/gfm_stats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
640 of 671 – 95.4% TOTAL
575 of 640 – 89.8% TOTAL Strict
578 of 640 – 90.3% TOTAL Strict