Add caseSensitive parameter on the InlineSyntax constructor (#400)
diff --git a/lib/src/inline_parser.dart b/lib/src/inline_parser.dart
index e9c5f84..954e605 100644
--- a/lib/src/inline_parser.dart
+++ b/lib/src/inline_parser.dart
@@ -351,8 +351,12 @@
///
/// If [startCharacter] is passed, it is used as a pre-matching check which
/// is faster than matching against [pattern].
- InlineSyntax(String pattern, {int? startCharacter})
- : pattern = RegExp(pattern, multiLine: true),
+ ///
+ /// If [caseSensitive] is disabled, then case is ignored when matching
+ /// the [pattern].
+ InlineSyntax(String pattern, {int? startCharacter, bool caseSensitive = true})
+ : pattern =
+ RegExp(pattern, multiLine: true, caseSensitive: caseSensitive),
_startCharacter = startCharacter;
/// Tries to match at the parser's current position.
diff --git a/test/html_renderer_test.dart b/test/html_renderer_test.dart
index d478fc7..35ac762 100644
--- a/test/html_renderer_test.dart
+++ b/test/html_renderer_test.dart
@@ -77,4 +77,39 @@
);
});
});
+
+ group('test InlineSyntax caseSensitive parameter', () {
+ const text = 'one BREAK two';
+
+ test('with caseSensitive enabled', () {
+ final result = markdownToHtml(
+ text,
+ inlineOnly: true,
+ inlineSyntaxes: [_BreakSyntax(true)],
+ );
+
+ expect(result, equals('one BREAK two'));
+ });
+
+ test('with caseSensitive disabled', () {
+ final result = markdownToHtml(
+ text,
+ inlineOnly: true,
+ inlineSyntaxes: [_BreakSyntax(false)],
+ );
+
+ expect(result, equals('one <break /> two'));
+ });
+ });
+}
+
+class _BreakSyntax extends InlineSyntax {
+ _BreakSyntax(bool caseSensitive)
+ : super('break', caseSensitive: caseSensitive);
+
+ @override
+ bool onMatch(InlineParser parser, Match match) {
+ parser.addNode(Element.empty('break'));
+ return true;
+ }
}