Skip to content

Commit

Permalink
Make use of thematic break lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
dikmax committed Jan 25, 2017
1 parent 0550790 commit 3790ed0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 6 additions & 4 deletions lib/src/parsers/blockquote_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,9 @@ class BlockquoteListParser extends AbstractParser<BlockNodeImpl> {
: lineResult.value;

// Checking for thematic break;
final Match match = thematicBreakTest.firstMatch(thematicTest);
if (match != null && match[1].length < stack.last.marker.endIndent) {
final int thematicTestIndent = skipIndent(thematicTest, 0);
if (thematicBreakLookup.isFound(thematicTest, thematicTestIndent)
&& thematicTestIndent < stack.last.marker.endIndent) {
// This line should be treated as standalone thematic break.
stack.flush(stackIndex, result);
markers = markers.take(markersIndex);
Expand Down Expand Up @@ -842,8 +843,9 @@ class BlockquoteListParser extends AbstractParser<BlockNodeImpl> {
}

// Checking for thematic break;
final Match match = thematicBreakTest.firstMatch(thematicTest);
if (match != null && match[1].length < stack.last.marker.endIndent) {
final int thematicTestIndent = skipIndent(thematicTest, 0);
if (thematicBreakLookup.isFound(thematicTest, thematicTestIndent)
&& thematicTestIndent < stack.last.marker.endIndent) {
// This line should be treated as standalone thematic break.
break;
}
Expand Down
3 changes: 0 additions & 3 deletions lib/src/parsers/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ Set<int> get escapableCodes {
return _escapableCodesSet;
}

final RegExp thematicBreakTest = new RegExp(
'^( {0,3})((?:\\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})\$');

final Pattern htmlBlock6Test = new RegExp(
r'</?([a-zA-Z1-6]+)(?:\s|/?>|$)',
);
Expand Down
5 changes: 3 additions & 2 deletions lib/src/parsers/thematic_break.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:mdown/src/parse_result.dart';
import 'package:mdown/src/parsers/abstract.dart';
import 'package:mdown/src/parsers/common.dart';
import 'package:mdown/src/parsers/container.dart';
import 'package:mdown/src/lookup.dart';

/// Parser for thematic break.
class ThematicBreakParser extends AbstractParser<BlockNodeImpl> {
Expand All @@ -17,8 +18,8 @@ class ThematicBreakParser extends AbstractParser<BlockNodeImpl> {
container.lineParser.parse(text, offset);
assert(lineResult.isSuccess);

final Match match = thematicBreakTest.firstMatch(lineResult.value);
if (match == null) {
final int indent = skipIndent(text, offset);
if (!thematicBreakLookup.isFound(text, indent)) {
return const ParseResult<BlockNodeImpl>.failure();
}

Expand Down

0 comments on commit 3790ed0

Please sign in to comment.