From 5dd444daf23f08e0a2945d7bf9abe3fc19d606a8 Mon Sep 17 00:00:00 2001 From: Krille Date: Thu, 28 Sep 2023 08:09:17 +0200 Subject: [PATCH] refactor: Update markdown --- lib/src/utils/markdown.dart | 23 ++++++++++++++--------- pubspec.yaml | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/src/utils/markdown.dart b/lib/src/utils/markdown.dart index 56507908..9957d36a 100644 --- a/lib/src/utils/markdown.dart +++ b/lib/src/utils/markdown.dart @@ -32,12 +32,17 @@ class LinebreakSyntax extends InlineSyntax { } } -class SpoilerSyntax extends TagSyntax { +class SpoilerSyntax extends DelimiterSyntax { SpoilerSyntax() : super(r'\|\|', requiresDelimiterRun: true); @override - Node close(InlineParser parser, Delimiter opener, Delimiter closer, - {required List Function() getChildren}) { + Iterable? close( + InlineParser parser, + Delimiter opener, + Delimiter closer, { + required String tag, + required List Function() getChildren, + }) { final children = getChildren(); final newChildren = []; var searchingForReason = true; @@ -67,7 +72,7 @@ class SpoilerSyntax extends TagSyntax { Element('span', searchingForReason ? children : newChildren); element.attributes['data-mx-spoiler'] = searchingForReason ? '' : htmlAttrEscape.convert(reason); - return element; + return [element]; } } @@ -110,7 +115,7 @@ class EmoteSyntax extends InlineSyntax { } } -class InlineLatexSyntax extends TagSyntax { +class InlineLatexSyntax extends DelimiterSyntax { InlineLatexSyntax() : super(r'\$([^\s$]([^\$]*[^\s$])?)\$'); @override @@ -131,16 +136,16 @@ class BlockLatexSyntax extends BlockSyntax { final endPattern = RegExp(r'^(.*)\$\$\s*$'); @override - List parseChildLines(BlockParser parser) { - final childLines = []; + List parseChildLines(BlockParser parser) { + final childLines = []; var first = true; while (!parser.isDone) { - final match = endPattern.firstMatch(parser.current); + final match = endPattern.firstMatch(parser.current.content); if (match == null || (first && match[1]!.trim().isEmpty)) { childLines.add(parser.current); parser.advance(); } else { - childLines.add(match[1]!); + childLines.add(Line(match[1]!)); parser.advance(); break; } diff --git a/pubspec.yaml b/pubspec.yaml index 495a867f..8b0e9f63 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: http: ^0.13.0 image: ^4.0.15 js: ^0.6.3 - markdown: ^4.0.0 + markdown: ^7.1.1 matrix_api_lite: ^1.7.0 mime: ^1.0.0 olm: ^2.0.2