From ffad7f806803da90abf737363b30179b844b3bfe Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 19 Nov 2025 16:07:06 -0800 Subject: [PATCH] Bump min Dart SDK to 3.9, reformat --- .github/workflows/markdown.yaml | 2 +- pkgs/markdown/CHANGELOG.md | 2 +- pkgs/markdown/analysis_options.yaml | 3 +- pkgs/markdown/example/app.dart | 4 +- .../markdown/lib/src/assets/case_folding.dart | 2 +- .../lib/src/assets/html_entities.dart | 2 +- pkgs/markdown/lib/src/ast.dart | 12 +- pkgs/markdown/lib/src/block_parser.dart | 8 +- .../block_syntaxes/alert_block_syntax.dart | 11 +- .../lib/src/block_syntaxes/block_syntax.dart | 19 +- .../src/block_syntaxes/blockquote_syntax.dart | 5 +- .../src/block_syntaxes/code_block_syntax.dart | 10 +- .../fenced_code_block_syntax.dart | 12 +- .../block_syntaxes/footnote_def_syntax.dart | 10 +- .../link_reference_definition_syntax.dart | 7 +- .../lib/src/block_syntaxes/list_syntax.dart | 40 ++- .../lib/src/block_syntaxes/table_syntax.dart | 2 +- pkgs/markdown/lib/src/document.dart | 17 +- pkgs/markdown/lib/src/extension_set.dart | 76 +++-- pkgs/markdown/lib/src/html_renderer.dart | 26 +- pkgs/markdown/lib/src/inline_parser.dart | 74 ++--- .../autolink_extension_syntax.dart | 9 +- .../src/inline_syntaxes/autolink_syntax.dart | 5 +- .../inline_syntaxes/color_swatch_syntax.dart | 12 +- .../inline_syntaxes/decode_html_syntax.dart | 7 +- .../src/inline_syntaxes/delimiter_syntax.dart | 96 ++++--- .../src/inline_syntaxes/emphasis_syntax.dart | 26 +- .../src/inline_syntaxes/escape_syntax.dart | 2 +- .../inline_syntaxes/footnote_ref_syntax.dart | 6 +- .../lib/src/inline_syntaxes/image_syntax.dart | 5 +- .../inline_syntaxes/inline_html_syntax.dart | 9 +- .../src/inline_syntaxes/inline_syntax.dart | 5 +- .../lib/src/inline_syntaxes/link_syntax.dart | 20 +- .../inline_syntaxes/strikethrough_syntax.dart | 14 +- pkgs/markdown/lib/src/line.dart | 6 +- pkgs/markdown/lib/src/patterns.dart | 23 +- pkgs/markdown/lib/src/util.dart | 11 +- pkgs/markdown/pubspec.yaml | 2 +- pkgs/markdown/test/crash_test.dart | 144 +++++----- pkgs/markdown/test/document_test.dart | 42 +-- pkgs/markdown/test/html_renderer_test.dart | 11 +- pkgs/markdown/test/markdown_test.dart | 262 ++++++++++-------- pkgs/markdown/test/util.dart | 5 +- pkgs/markdown/test/util_test.dart | 33 +-- pkgs/markdown/test/version_test.dart | 6 +- pkgs/markdown/tool/dartdoc_compare.dart | 19 +- pkgs/markdown/tool/expected_output.dart | 11 +- pkgs/markdown/tool/stats.dart | 62 +++-- pkgs/markdown/tool/stats_lib.dart | 20 +- pkgs/markdown/tool/update_case_folding.dart | 8 +- pkgs/markdown/tool/update_emojis.dart | 10 +- pkgs/markdown/tool/update_entities.dart | 10 +- pkgs/markdown/tool/update_github_emojis.dart | 78 +++--- 53 files changed, 689 insertions(+), 634 deletions(-) diff --git a/.github/workflows/markdown.yaml b/.github/workflows/markdown.yaml index eee44c33f..3659a6688 100644 --- a/.github/workflows/markdown.yaml +++ b/.github/workflows/markdown.yaml @@ -70,7 +70,7 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [3.4, dev] + sdk: [3.9, dev] steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 - uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index e7dc32ebd..88b1236f3 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md @@ -10,7 +10,7 @@ * Fix an issue with nested list structure when indented by tabs (#2172). * Deprecated `LinkContext` and `BlockParser.standardBlockSyntaxes`. Implementation members that should never have been made public. -* Require Dart `^3.4.0`. +* Require Dart `^3.9.0`. ## 7.3.0 diff --git a/pkgs/markdown/analysis_options.yaml b/pkgs/markdown/analysis_options.yaml index 76bf2549e..f293d1992 100644 --- a/pkgs/markdown/analysis_options.yaml +++ b/pkgs/markdown/analysis_options.yaml @@ -23,8 +23,9 @@ linter: - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list - prefer_const_declarations - - prefer_final_locals - prefer_final_in_for_each + - prefer_final_locals + - remove_deprecations_in_breaking_versions - unnecessary_await_in_return - unnecessary_raw_strings - use_if_null_to_convert_nulls_to_bools diff --git a/pkgs/markdown/example/app.dart b/pkgs/markdown/example/app.dart index 51d560f19..3d15383fd 100644 --- a/pkgs/markdown/example/app.dart +++ b/pkgs/markdown/example/app.dart @@ -131,9 +131,7 @@ void _switchFlavor(Event e) { } extension on NodeList { - List get items => [ - for (var i = 0; i < length; i++) item(i)!, - ]; + List get items => [for (var i = 0; i < length; i++) item(i)!]; } extension on NamedNodeMap { diff --git a/pkgs/markdown/lib/src/assets/case_folding.dart b/pkgs/markdown/lib/src/assets/case_folding.dart index 09081aa46..7c1d6ecbc 100644 --- a/pkgs/markdown/lib/src/assets/case_folding.dart +++ b/pkgs/markdown/lib/src/assets/case_folding.dart @@ -1312,5 +1312,5 @@ const caseFoldingMap = { "𞤞": "𞥀", "𞤟": "𞥁", "𞤠": "𞥂", - "𞤡": "𞥃" + "𞤡": "𞥃", }; diff --git a/pkgs/markdown/lib/src/assets/html_entities.dart b/pkgs/markdown/lib/src/assets/html_entities.dart index 2599762f7..50d111a87 100644 --- a/pkgs/markdown/lib/src/assets/html_entities.dart +++ b/pkgs/markdown/lib/src/assets/html_entities.dart @@ -2129,5 +2129,5 @@ const htmlEntitiesMap = { "𝕫": "𝕫", "𝓏": "𝓏", "‍": "‍", - "‌": "‌" + "‌": "‌", }; diff --git a/pkgs/markdown/lib/src/ast.dart b/pkgs/markdown/lib/src/ast.dart index e5530cb3e..3a5c1677e 100644 --- a/pkgs/markdown/lib/src/ast.dart +++ b/pkgs/markdown/lib/src/ast.dart @@ -25,19 +25,15 @@ class Element implements Node { Element(this.tag, this.children) : attributes = {}; /// Instantiates an empty, self-closing [tag] Element. - Element.empty(this.tag) - : children = null, - attributes = {}; + Element.empty(this.tag) : children = null, attributes = {}; /// Instantiates a [tag] Element with no [children]. - Element.withTag(this.tag) - : children = const [], - attributes = {}; + Element.withTag(this.tag) : children = const [], attributes = {}; /// Instantiates a [tag] Element with a single Text child. Element.text(this.tag, String text) - : children = [Text(text)], - attributes = {}; + : children = [Text(text)], + attributes = {}; /// Whether this element is self-closing. bool get isEmpty => children == null; diff --git a/pkgs/markdown/lib/src/block_parser.dart b/pkgs/markdown/lib/src/block_parser.dart index 28d4b2797..0db23d7c7 100644 --- a/pkgs/markdown/lib/src/block_parser.dart +++ b/pkgs/markdown/lib/src/block_parser.dart @@ -58,8 +58,10 @@ class BlockParser { /// The collection of built-in block parsers. // TODO(kevmoo): this should be static const and private! // The fact that it's mutable is a BUG! - @Deprecated('Implementation member. ' - 'Will be removed or make static in the next release.') + @Deprecated( + 'Implementation member. ' + 'Will be removed or make static in the next release.', + ) final List standardBlockSyntaxes = [ const EmptyBlockSyntax(), const HtmlBlockSyntax(), @@ -71,7 +73,7 @@ class BlockParser { const UnorderedListSyntax(), const OrderedListSyntax(), const LinkReferenceDefinitionSyntax(), - const ParagraphSyntax() + const ParagraphSyntax(), ]; BlockParser(this.lines, this.document) { diff --git a/pkgs/markdown/lib/src/block_syntaxes/alert_block_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/alert_block_syntax.dart index 0f4f5b11a..903e65a89 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/alert_block_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/alert_block_syntax.dart @@ -57,8 +57,9 @@ class AlertBlockSyntax extends BlockSyntax { // a Setext header. // Because indented code blocks cannot interrupt paragraphs, a line // matched CodeBlockSyntax is also paragraph continuation text. - final otherMatched = - parser.blockSyntaxes.firstWhere((s) => s.canParse(parser)); + final otherMatched = parser.blockSyntaxes.firstWhere( + (s) => s.canParse(parser), + ); if ((otherMatched is ParagraphSyntax && !lastLine.isBlankLine && !codeFencePattern.hasMatch(lastLine.content)) || @@ -78,8 +79,10 @@ class AlertBlockSyntax extends BlockSyntax { @override Node parse(BlockParser parser) { // Parse the alert type from the first line. - final type = - pattern.firstMatch(parser.current.content)!.group(1)!.toLowerCase(); + final type = pattern + .firstMatch(parser.current.content)! + .group(1)! + .toLowerCase(); parser.advance(); final childLines = parseChildLines(parser); // Recursively parse the contents of the alert. diff --git a/pkgs/markdown/lib/src/block_syntaxes/block_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/block_syntax.dart index 947824ab6..bd49c8c11 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/block_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/block_syntax.dart @@ -50,15 +50,18 @@ abstract class BlockSyntax { /// Gets whether or not [parser]'s current line should end the previous block. static bool isAtBlockEnd(BlockParser parser) { if (parser.isDone) return true; - return parser.blockSyntaxes - .any((s) => s.canParse(parser) && s.canEndBlock(parser)); + return parser.blockSyntaxes.any( + (s) => s.canParse(parser) && s.canEndBlock(parser), + ); } /// Generates a valid HTML anchor from the inner text of [element]. - static String generateAnchorHash(Element element) => - element.children!.first.textContent - .toLowerCase() - .trim() - .replaceAll(RegExp('[^a-z0-9 _-]'), '') - .replaceAll(RegExp(r'\s'), '-'); + static String generateAnchorHash(Element element) => element + .children! + .first + .textContent + .toLowerCase() + .trim() + .replaceAll(RegExp('[^a-z0-9 _-]'), '') + .replaceAll(RegExp(r'\s'), '-'); } diff --git a/pkgs/markdown/lib/src/block_syntaxes/blockquote_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/blockquote_syntax.dart index afbe23a0f..a0da1f21f 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/blockquote_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/blockquote_syntax.dart @@ -63,8 +63,9 @@ class BlockquoteSyntax extends BlockSyntax { // a Setext header. // Because indented code blocks cannot interrupt paragraphs, a line // matched CodeBlockSyntax is also paragraph continuation text. - final otherMatched = - parser.blockSyntaxes.firstWhere((s) => s.canParse(parser)); + final otherMatched = parser.blockSyntaxes.firstWhere( + (s) => s.canParse(parser), + ); if ((otherMatched is ParagraphSyntax && !lastLine.isBlankLine && !codeFencePattern.hasMatch(lastLine.content)) || diff --git a/pkgs/markdown/lib/src/block_syntaxes/code_block_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/code_block_syntax.dart index 1d30667a5..b35b8f968 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/code_block_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/code_block_syntax.dart @@ -35,10 +35,12 @@ class CodeBlockSyntax extends BlockSyntax { break; } - childLines.add(Line( - parser.current.content.dedent().text, - tabRemaining: parser.current.tabRemaining, - )); + childLines.add( + Line( + parser.current.content.dedent().text, + tabRemaining: parser.current.tabRemaining, + ), + ); parser.advance(); } diff --git a/pkgs/markdown/lib/src/block_syntaxes/fenced_code_block_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/fenced_code_block_syntax.dart index c6a4f52e1..7954e0e42 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/fenced_code_block_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/fenced_code_block_syntax.dart @@ -43,15 +43,19 @@ class FencedCodeBlockSyntax extends BlockSyntax { final code = Element.text('code', text); if (languageString != null) { - final processedLanguage = _processAttribute(languageString, - encodeHtml: parser.document.encodeHtml); + final processedLanguage = _processAttribute( + languageString, + encodeHtml: parser.document.encodeHtml, + ); code.attributes['class'] = 'language-$processedLanguage'; } final pre = Element('pre', [code]); if (metadataString != null) { - final processedMetadata = _processAttribute(metadataString, - encodeHtml: parser.document.encodeHtml); + final processedMetadata = _processAttribute( + metadataString, + encodeHtml: parser.document.encodeHtml, + ); pre.attributes['data-metadata'] = processedMetadata; } diff --git a/pkgs/markdown/lib/src/block_syntaxes/footnote_def_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/footnote_def_syntax.dart index 3e59dcf71..54b663f1e 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/footnote_def_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/footnote_def_syntax.dart @@ -43,8 +43,9 @@ class FootnoteDefSyntax extends BlockSyntax { final children = []; // As one empty line should not split footnote definition, use this flag. var shouldBeBlock = false; - late final syntaxList = parser.blockSyntaxes - .where((s) => !_excludingPattern.contains(s.pattern)); + late final syntaxList = parser.blockSyntaxes.where( + (s) => !_excludingPattern.contains(s.pattern), + ); // Every line is footnote's children util two blank lines or a block. while (!parser.isDone) { @@ -69,10 +70,7 @@ class FootnoteDefSyntax extends BlockSyntax { } /// Patterns that would be used to decide if one line is a block. - static final _excludingPattern = { - emptyPattern, - dummyPattern, - }; + static final _excludingPattern = {emptyPattern, dummyPattern}; /// Whether this line is any kind of block. /// If `true`, the footnote block should end. diff --git a/pkgs/markdown/lib/src/block_syntaxes/link_reference_definition_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/link_reference_definition_syntax.dart index 5b2b1b5fd..f688e7b5f 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/link_reference_definition_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/link_reference_definition_syntax.dart @@ -53,11 +53,8 @@ class LinkReferenceDefinitionSyntax extends BlockSyntax { parser.document.linkReferences.putIfAbsent( labelString, - () => LinkReference( - labelString, - linkParser.destination!, - linkParser.title, - ), + () => + LinkReference(labelString, linkParser.destination!, linkParser.title), ); return true; diff --git a/pkgs/markdown/lib/src/block_syntaxes/list_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/list_syntax.dart index 5aa0865c2..c4fc4a74e 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/list_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/list_syntax.dart @@ -14,10 +14,7 @@ import 'ordered_list_with_checkbox_syntax.dart'; import 'unordered_list_with_checkbox_syntax.dart'; class ListItem { - const ListItem( - this.lines, { - this.taskListItemState, - }); + const ListItem(this.lines, {this.taskListItemState}); final List lines; final TaskListItemState? taskListItemState; @@ -78,7 +75,8 @@ abstract class ListSyntax extends BlockSyntax { final match = pattern.firstMatch(parser.current.content); final ordered = match![1] != null; - final taskListParserEnabled = this is UnorderedListWithCheckboxSyntax || + final taskListParserEnabled = + this is UnorderedListWithCheckboxSyntax || this is OrderedListWithCheckboxSyntax; final items = []; var childLines = []; @@ -123,7 +121,8 @@ abstract class ListSyntax extends BlockSyntax { int? blankLines; while (!parser.isDone) { - final currentIndent = parser.current.content.indentation() + + final currentIndent = + parser.current.content.indentation() + (parser.current.tabRemaining ?? 0); if (parser.current.isBlankLine) { @@ -141,12 +140,14 @@ abstract class ListSyntax extends BlockSyntax { final indentedLine = parser.current.content.dedent(indent); - childLines.add(Line( - blankLines == null - ? indentedLine.text - : parseTaskListItem(indentedLine.text), - tabRemaining: indentedLine.tabRemaining, - )); + childLines.add( + Line( + blankLines == null + ? indentedLine.text + : parseTaskListItem(indentedLine.text), + tabRemaining: indentedLine.tabRemaining, + ), + ); } else if (tryMatch(hrPattern)) { // Horizontal rule takes precedence to a new list item. break; @@ -164,10 +165,7 @@ abstract class ListSyntax extends BlockSyntax { textParser.advance(); // See https://spec.commonmark.org/0.30/#ordered-list-marker - final marker = textParser.substring( - markerStart, - textParser.pos, - ); + final marker = textParser.substring(markerStart, textParser.pos); var isBlank = true; var contentWhitespances = 0; @@ -211,7 +209,8 @@ abstract class ListSyntax extends BlockSyntax { // any indentation past the required whitespace character. indent = precedingWhitespaces; } else { - indent = precedingWhitespaces + + indent = + precedingWhitespaces + contentWhitespances + (parser.current.tabRemaining ?? 0); } @@ -225,10 +224,7 @@ abstract class ListSyntax extends BlockSyntax { content = content.prependSpace(2); } - childLines.add(Line( - content, - tabRemaining: containsTab ? 2 : null, - )); + childLines.add(Line(content, tabRemaining: containsTab ? 2 : null)); } else if (BlockSyntax.isAtBlockEnd(parser)) { // Done with the list. break; @@ -271,7 +267,7 @@ abstract class ListSyntax extends BlockSyntax { final itemElement = checkboxToInsert == null ? Element('li', children) : (Element('li', _addCheckbox(children, checkboxToInsert)) - ..attributes['class'] = taskListClass); + ..attributes['class'] = taskListClass); itemNodes.add(itemElement); anyEmptyLinesBetweenBlocks = diff --git a/pkgs/markdown/lib/src/block_syntaxes/table_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/table_syntax.dart index 89cbd905f..058e4b807 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/table_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/table_syntax.dart @@ -175,7 +175,7 @@ class TableSyntax extends BlockSyntax { } parser.advance(); final row = [ - for (final cell in cells) Element(cellType, [UnparsedContent(cell)]) + for (final cell in cells) Element(cellType, [UnparsedContent(cell)]), ]; for (var i = 0; i < row.length && i < alignments.length; i++) { diff --git a/pkgs/markdown/lib/src/document.dart b/pkgs/markdown/lib/src/document.dart index f33ff33ff..ba391d1f1 100644 --- a/pkgs/markdown/lib/src/document.dart +++ b/pkgs/markdown/lib/src/document.dart @@ -52,8 +52,9 @@ class Document { this.encodeHtml = true, this.withDefaultBlockSyntaxes = true, this.withDefaultInlineSyntaxes = true, - }) : hasCustomInlineSyntaxes = (inlineSyntaxes?.isNotEmpty ?? false) || - (extensionSet?.inlineSyntaxes.isNotEmpty ?? false) { + }) : hasCustomInlineSyntaxes = + (inlineSyntaxes?.isNotEmpty ?? false) || + (extensionSet?.inlineSyntaxes.isNotEmpty ?? false) { if (blockSyntaxes != null) { _blockSyntaxes.addAll(blockSyntaxes); } @@ -157,8 +158,8 @@ class Document { final refs = [ for (var i = 0; i < count; i++) ...[ Text(' '), - _ElementExt.footnoteAnchor(ref, i) - ] + _ElementExt.footnoteAnchor(ref, i), + ], ]; if (children.isEmpty) { children.addAll(refs); @@ -180,10 +181,10 @@ extension _ElementExt on Element { final e = Element.empty('tag'); e.match; return Element('a', [ - Text('\u21a9'), - if (i > 0) - Element('sup', [Text(num)])..attributes['class'] = 'footnote-ref', - ]) + Text('\u21a9'), + if (i > 0) + Element('sup', [Text(num)])..attributes['class'] = 'footnote-ref', + ]) // Ignore GFM's attributes: // . ..attributes['href'] = '#fnref-$ref$suffix' diff --git a/pkgs/markdown/lib/src/extension_set.dart b/pkgs/markdown/lib/src/extension_set.dart index 58a25d86a..46e66f99d 100644 --- a/pkgs/markdown/lib/src/extension_set.dart +++ b/pkgs/markdown/lib/src/extension_set.dart @@ -34,12 +34,10 @@ class ExtensionSet { /// /// [CommonMark]: http://commonmark.org/ static final ExtensionSet commonMark = ExtensionSet( - List.unmodifiable( - [const FencedCodeBlockSyntax()], - ), - List.unmodifiable( - [InlineHtmlSyntax()], - ), + List.unmodifiable([ + const FencedCodeBlockSyntax(), + ]), + List.unmodifiable([InlineHtmlSyntax()]), ); /// The [gitHubWeb] extension set renders Markdown similarly to GitHub. @@ -52,48 +50,40 @@ class ExtensionSet { /// /// [GitHub flavored Markdown]: https://github.github.com/gfm/ static final ExtensionSet gitHubWeb = ExtensionSet( - List.unmodifiable( - [ - const FencedCodeBlockSyntax(), - const HeaderWithIdSyntax(), - const SetextHeaderWithIdSyntax(), - const TableSyntax(), - const UnorderedListWithCheckboxSyntax(), - const OrderedListWithCheckboxSyntax(), - const FootnoteDefSyntax(), - const AlertBlockSyntax(), - ], - ), - List.unmodifiable( - [ - InlineHtmlSyntax(), - StrikethroughSyntax(), - EmojiSyntax(), - ColorSwatchSyntax(), - AutolinkExtensionSyntax() - ], - ), + List.unmodifiable([ + const FencedCodeBlockSyntax(), + const HeaderWithIdSyntax(), + const SetextHeaderWithIdSyntax(), + const TableSyntax(), + const UnorderedListWithCheckboxSyntax(), + const OrderedListWithCheckboxSyntax(), + const FootnoteDefSyntax(), + const AlertBlockSyntax(), + ]), + List.unmodifiable([ + InlineHtmlSyntax(), + StrikethroughSyntax(), + EmojiSyntax(), + ColorSwatchSyntax(), + AutolinkExtensionSyntax(), + ]), ); /// The [gitHubFlavored] extension set is close to compliance with the /// [GitHub flavored Markdown spec](https://github.github.com/gfm/). static final ExtensionSet gitHubFlavored = ExtensionSet( - List.unmodifiable( - [ - const FencedCodeBlockSyntax(), - const TableSyntax(), - const UnorderedListWithCheckboxSyntax(), - const OrderedListWithCheckboxSyntax(), - const FootnoteDefSyntax(), - ], - ), - List.unmodifiable( - [ - InlineHtmlSyntax(), - StrikethroughSyntax(), - AutolinkExtensionSyntax() - ], - ), + List.unmodifiable([ + const FencedCodeBlockSyntax(), + const TableSyntax(), + const UnorderedListWithCheckboxSyntax(), + const OrderedListWithCheckboxSyntax(), + const FootnoteDefSyntax(), + ]), + List.unmodifiable([ + InlineHtmlSyntax(), + StrikethroughSyntax(), + AutolinkExtensionSyntax(), + ]), ); final List blockSyntaxes; diff --git a/pkgs/markdown/lib/src/html_renderer.dart b/pkgs/markdown/lib/src/html_renderer.dart index 404d870db..7a3790f5f 100644 --- a/pkgs/markdown/lib/src/html_renderer.dart +++ b/pkgs/markdown/lib/src/html_renderer.dart @@ -44,9 +44,7 @@ String markdownToHtml( /// Renders [nodes] to HTML. String renderToHtml(List nodes, {bool enableTagfilter = false}) => - HtmlRenderer( - enableTagfilter: enableTagfilter, - ).render(nodes); + HtmlRenderer(enableTagfilter: enableTagfilter).render(nodes); const _blockTags = [ 'blockquote', @@ -95,9 +93,8 @@ class HtmlRenderer implements NodeVisitor { String? _lastVisitedTag; final bool _tagfilterEnabled; - HtmlRenderer({ - bool enableTagfilter = false, - }) : _tagfilterEnabled = enableTagfilter; + HtmlRenderer({bool enableTagfilter = false}) + : _tagfilterEnabled = enableTagfilter; String render(List nodes) { buffer = StringBuffer(); @@ -207,12 +204,13 @@ class HtmlRenderer implements NodeVisitor { // As said in the specification, this process should happen when rendering // HTML output, so there should not be a dedicated syntax for this extension. String _filterTags(String content) => content.replaceAll( - RegExp( - '<(?=(?:' - 'title|textarea|style|xmp|iframe|noembed|noframes|script|plaintext' - ')>)', - caseSensitive: false, - multiLine: true, - ), - '<'); + RegExp( + '<(?=(?:' + 'title|textarea|style|xmp|iframe|noembed|noframes|script|plaintext' + ')>)', + caseSensitive: false, + multiLine: true, + ), + '<', + ); } diff --git a/pkgs/markdown/lib/src/inline_parser.dart b/pkgs/markdown/lib/src/inline_parser.dart index e700ecfd1..736c2fec3 100644 --- a/pkgs/markdown/lib/src/inline_parser.dart +++ b/pkgs/markdown/lib/src/inline_parser.dart @@ -23,8 +23,8 @@ import 'inline_syntaxes/text_syntax.dart'; /// Maintains the internal state needed to parse inline span elements in /// Markdown. class InlineParser { - static final List _defaultSyntaxes = - List.unmodifiable([ + static final List + _defaultSyntaxes = List.unmodifiable([ EmailAutolinkSyntax(), AutolinkSyntax(), LineBreakSyntax(), @@ -80,7 +80,7 @@ class InlineParser { EscapeSyntax(), DecodeHtmlSyntax(), LinkSyntax(linkResolver: document.linkResolver), - ImageSyntax(linkResolver: document.imageLinkResolver) + ImageSyntax(linkResolver: document.imageLinkResolver), ]); syntaxes.addAll(_defaultSyntaxes); @@ -127,8 +127,9 @@ class InlineParser { /// This is the "look for link or image" routine from the CommonMark spec: /// https://spec.commonmark.org/0.30/#look-for-link-or-image. void _linkOrImage() { - final index = _delimiterStack - .lastIndexWhere((d) => d.char == $lbracket || d.char == $exclamation); + final index = _delimiterStack.lastIndexWhere( + (d) => d.char == $lbracket || d.char == $exclamation, + ); if (index == -1) { // Never found a possible open bracket. This is just a literal "]". addNode(Text(']')); @@ -147,14 +148,19 @@ class InlineParser { final syntax = delimiter.syntax; if (syntax is LinkSyntax && syntaxes.any((e) => e is LinkSyntax)) { final nodeIndex = _tree.lastIndexWhere((n) => n == delimiter.node); - final linkNodes = syntax.close(this, delimiter, null, getChildren: () { - _processDelimiterRun(index); - // All of the nodes which lie past [index] are children of this - // link/image. - final children = _tree.sublist(nodeIndex + 1, _tree.length); - _tree.removeRange(nodeIndex + 1, _tree.length); - return children; - }); + final linkNodes = syntax.close( + this, + delimiter, + null, + getChildren: () { + _processDelimiterRun(index); + // All of the nodes which lie past [index] are children of this + // link/image. + final children = _tree.sublist(nodeIndex + 1, _tree.length); + _tree.removeRange(nodeIndex + 1, _tree.length); + return children; + }, + ); if (linkNodes != null) { _delimiterStack.removeAt(index); if (delimiter.char == $lbracket) { @@ -171,8 +177,10 @@ class InlineParser { advanceBy(1); } } else { - throw StateError('Non-link syntax delimiter found with character ' - '"${delimiter.char}"'); + throw StateError( + 'Non-link syntax delimiter found with character ' + '"${delimiter.char}"', + ); } } @@ -209,9 +217,10 @@ class InlineParser { final openersBottomPerCloserLength = openersBottom[closer.char]!; final openerBottom = openersBottomPerCloserLength[closer.length % 3]; final openerIndex = _delimiterStack.lastIndexWhere( - (d) => - d.char == closer.char && d.canOpen && _canFormEmphasis(d, closer), - currentIndex - 1); + (d) => + d.char == closer.char && d.canOpen && _canFormEmphasis(d, closer), + currentIndex - 1, + ); if (openerIndex > bottomIndex && openerIndex > openerBottom) { // Found an opener for [closer]. final opener = _delimiterStack[openerIndex]; @@ -219,9 +228,11 @@ class InlineParser { currentIndex++; continue; } - final matchedTagIndex = opener.tags.lastIndexWhere((e) => - opener.length >= e.indicatorLength && - closer.length >= e.indicatorLength); + final matchedTagIndex = opener.tags.lastIndexWhere( + (e) => + opener.length >= e.indicatorLength && + closer.length >= e.indicatorLength, + ); if (matchedTagIndex == -1) { currentIndex++; continue; @@ -237,10 +248,8 @@ class InlineParser { opener, closer, tag: matchedTag.tag, - getChildren: () => _tree.sublist( - openerTextNodeIndex + 1, - closerTextNodeIndex, - ), + getChildren: () => + _tree.sublist(openerTextNodeIndex + 1, closerTextNodeIndex), ); // Replace all of the nodes between the opener and the closer (which // are now the new emphasis node's children) with the emphasis node. @@ -265,8 +274,9 @@ class InlineParser { currentIndex--; closerTextNodeIndex--; } else { - final newOpenerTextNode = - Text(openerTextNode.text.substring(indicatorLength)); + final newOpenerTextNode = Text( + openerTextNode.text.substring(indicatorLength), + ); _tree[openerTextNodeIndex] = newOpenerTextNode; opener.node = newOpenerTextNode; } @@ -277,8 +287,9 @@ class InlineParser { // [currentIndex] has just moved to point at the next delimiter; // leave it. } else { - final newCloserTextNode = - Text(closerTextNode.text.substring(indicatorLength)); + final newCloserTextNode = Text( + closerTextNode.text.substring(indicatorLength), + ); _tree[closerTextNodeIndex] = newCloserTextNode; closer.node = newCloserTextNode; // [currentIndex] needs to be considered again; leave it. @@ -308,8 +319,9 @@ class InlineParser { continue; } if (node is Text && nodes[i + 1] is Text) { - final buffer = - StringBuffer('${node.textContent}${nodes[i + 1].textContent}'); + final buffer = StringBuffer( + '${node.textContent}${nodes[i + 1].textContent}', + ); var j = i + 2; while (j < nodes.length && nodes[j] is Text) { buffer.write(nodes[j].textContent); diff --git a/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart index 0333abb3d..77e21a95a 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart @@ -16,23 +16,19 @@ class AutolinkExtensionSyntax extends InlineSyntax { // Note: Disable this piece for now, as Safari does not support // lookarounds. Consider re-enabling later. // r'(?<=^|[\s*_~(>])' - // An extended url autolink will be recognised when one of the schemes // http://, or https://, followed by a valid domain. See // https://github.github.com/gfm/#extended-url-autolink. r'(?:(?:https?|ftp):\/\/|www\.)' - // A valid domain consists of segments of alphanumeric characters, // underscores (_) and hyphens (-) separated by periods (.). There must // be at least one period, and no underscores may be present in the last // two segments of the domain. See // https://github.github.com/gfm/#valid-domain. r'(?:[-_a-z0-9]+\.)*(?:[-a-z0-9]+\.[-a-z0-9]+)' - // After a valid domain, zero or more non-space non-< characters may // follow. r'[^\s<]*' - // Trailing punctuation (specifically, ?, !, ., ,, :, *, _, and ~) will // not be considered part of the autolink, though they may be included in // the interior of the link. See @@ -47,10 +43,7 @@ class AutolinkExtensionSyntax extends InlineSyntax { r'[-_.+a-z0-9]+@(?:[-_a-z0-9]+\.)+[-_a-z0-9]*[a-z0-9]'; AutolinkExtensionSyntax() - : super( - '($_linkPattern)|($_emailPattern)', - caseSensitive: false, - ); + : super('($_linkPattern)|($_emailPattern)', caseSensitive: false); @override bool tryMatch(InlineParser parser, [int? startMatchPos]) { diff --git a/pkgs/markdown/lib/src/inline_syntaxes/autolink_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/autolink_syntax.dart index 073c1cc22..01efd0cbe 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/autolink_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/autolink_syntax.dart @@ -18,8 +18,9 @@ class AutolinkSyntax extends InlineSyntax { final anchor = Element.text('a', text); final destination = normalizeLinkDestination(url); - anchor.attributes['href'] = - parser.encodeHtml ? escapeHtml(destination) : destination; + anchor.attributes['href'] = parser.encodeHtml + ? escapeHtml(destination) + : destination; parser.addNode(anchor); return true; diff --git a/pkgs/markdown/lib/src/inline_syntaxes/color_swatch_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/color_swatch_syntax.dart index e44fdbf5b..5955cd7eb 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/color_swatch_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/color_swatch_syntax.dart @@ -68,11 +68,13 @@ class ColorSwatchSyntax extends InlineSyntax { if (parser.encodeHtml) code = escapeHtml(code); - parser.addNode(Element('code', [ - Text(code), - Element.withTag('span')..attributes['style'] = 'background-color:$code;', - ]) - ..attributes['class'] = 'gfm-color_chip'); + parser.addNode( + Element('code', [ + Text(code), + Element.withTag('span') + ..attributes['style'] = 'background-color:$code;', + ])..attributes['class'] = 'gfm-color_chip', + ); return true; } diff --git a/pkgs/markdown/lib/src/inline_syntaxes/decode_html_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/decode_html_syntax.dart index 1af15d53c..7636b6cc7 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/decode_html_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/decode_html_syntax.dart @@ -14,8 +14,11 @@ import 'inline_syntax.dart'; // https://spec.commonmark.org/0.30/#entity-and-numeric-character-references class DecodeHtmlSyntax extends InlineSyntax { DecodeHtmlSyntax() - : super(htmlCharactersPattern.pattern, - caseSensitive: false, startCharacter: $ampersand); + : super( + htmlCharactersPattern.pattern, + caseSensitive: false, + startCharacter: $ampersand, + ); @override bool tryMatch(InlineParser parser, [int? startMatchPos]) { diff --git a/pkgs/markdown/lib/src/inline_syntaxes/delimiter_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/delimiter_syntax.dart index f26bdc9b3..5b18bd381 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/delimiter_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/delimiter_syntax.dart @@ -44,15 +44,17 @@ class DelimiterSyntax extends InlineSyntax { final matchEnd = parser.pos + runLength; final text = Text(parser.source.substring(matchStart, matchEnd)); if (!requiresDelimiterRun) { - parser.pushDelimiter(SimpleDelimiter( - node: text, - length: runLength, - char: parser.source.codeUnitAt(matchStart), - canOpen: true, - canClose: false, - syntax: this, - endPos: matchEnd, - )); + parser.pushDelimiter( + SimpleDelimiter( + node: text, + length: runLength, + char: parser.source.codeUnitAt(matchStart), + canOpen: true, + canClose: false, + syntax: this, + endPos: matchEnd, + ), + ); parser.addNode(text); return true; } @@ -194,33 +196,36 @@ class DelimiterRun implements Delimiter { // This RegExp is inspired by // https://github.com/commonmark/commonmark.js/blob/1f7d09099c20d7861a674674a5a88733f55ff729/lib/inlines.js#L39. // I don't know if there is any way to simplify it or maintain it. - static final unicodePunctuationPattern = RegExp('[' - '$asciiPunctuationEscaped' - r'\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE' - r'\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E' - r'\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E' - r'\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14' - r'\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB' - r'\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736' - r'\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F' - r'\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E' - r'\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051' - r'\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A' - r'\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC' - r'\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42' - r'\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE' - r'\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF' - r'\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF' - r'\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19' - r'\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03' - r'\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F' - r'\uFF5B\uFF5D\uFF5F-\uFF65' - ']'); + static final unicodePunctuationPattern = RegExp( + '[' + '$asciiPunctuationEscaped' + r'\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE' + r'\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E' + r'\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E' + r'\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14' + r'\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB' + r'\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736' + r'\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F' + r'\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E' + r'\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051' + r'\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A' + r'\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC' + r'\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42' + r'\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE' + r'\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF' + r'\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF' + r'\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19' + r'\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03' + r'\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F' + r'\uFF5B\uFF5D\uFF5F-\uFF65' + ']', + ); /// Unicode whitespace. // See https://spec.commonmark.org/0.30/#unicode-whitespace-character. // Unicode Zs: https://www.compart.com/en/unicode/category. - static const unicodeWhitespace = '\u0020\u0009\u000A\u000C\u000D' + static const unicodeWhitespace = + '\u0020\u0009\u000A\u000C\u000D' '\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008' '\u2009\u200A\u202F\u205F\u3000'; @@ -259,11 +264,13 @@ class DelimiterRun implements Delimiter { required bool isPrecededByPunctuation, required bool isFollowedByPunctuation, required this.allowIntraWord, - }) : canOpen = isLeftFlanking && - (!isRightFlanking || allowIntraWord || isPrecededByPunctuation), - canClose = isRightFlanking && - (!isLeftFlanking || allowIntraWord || isFollowedByPunctuation), - isActive = true; + }) : canOpen = + isLeftFlanking && + (!isRightFlanking || allowIntraWord || isPrecededByPunctuation), + canClose = + isRightFlanking && + (!isLeftFlanking || allowIntraWord || isFollowedByPunctuation), + isActive = true; /// Tries to parse a delimiter run from [runStart] (inclusive) to [runEnd] /// (exclusive). @@ -287,7 +294,8 @@ class DelimiterRun implements Delimiter { } else { final preceding = parser.source.substring(runStart - 1, runStart); precededByWhitespace = unicodeWhitespace.contains(preceding); - precededByPunctuation = !precededByWhitespace && + precededByPunctuation = + !precededByWhitespace && unicodePunctuationPattern.hasMatch(preceding); } @@ -297,20 +305,23 @@ class DelimiterRun implements Delimiter { } else { final following = parser.source.substring(runEnd, runEnd + 1); followedByWhitespace = unicodeWhitespace.contains(following); - followedByPunctuation = !followedByWhitespace && + followedByPunctuation = + !followedByWhitespace && unicodePunctuationPattern.hasMatch(following); } // If it is a left-flanking delimiter run, see // https://spec.commonmark.org/0.30/#left-flanking-delimiter-run. - final isLeftFlanking = !followedByWhitespace && + final isLeftFlanking = + !followedByWhitespace && (!followedByPunctuation || precededByWhitespace || precededByPunctuation); // If it is a right-flanking delimiter run, see // https://spec.commonmark.org/0.30/#right-flanking-delimiter-run. - final isRightFlanking = !precededByWhitespace && + final isRightFlanking = + !precededByWhitespace && (!precededByPunctuation || followedByWhitespace || followedByPunctuation); @@ -332,6 +343,7 @@ class DelimiterRun implements Delimiter { } @override - String toString() => ' + ''; } diff --git a/pkgs/markdown/lib/src/inline_syntaxes/emphasis_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/emphasis_syntax.dart index 58f2e7001..74fee68e4 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/emphasis_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/emphasis_syntax.dart @@ -8,22 +8,22 @@ import 'delimiter_syntax.dart'; class EmphasisSyntax extends DelimiterSyntax { /// Parses `__strong__` and `_emphasis_`. EmphasisSyntax.underscore() - : super( - '_+', - requiresDelimiterRun: true, - tags: _tags, - startCharacter: $underscore, - ); + : super( + '_+', + requiresDelimiterRun: true, + tags: _tags, + startCharacter: $underscore, + ); /// Parses `**strong**` and `*emphasis*`. EmphasisSyntax.asterisk() - : super( - r'\*+', - requiresDelimiterRun: true, - allowIntraWord: true, - tags: _tags, - startCharacter: $asterisk, - ); + : super( + r'\*+', + requiresDelimiterRun: true, + allowIntraWord: true, + tags: _tags, + startCharacter: $asterisk, + ); static final _tags = [DelimiterTag('em', 1), DelimiterTag('strong', 2)]; } diff --git a/pkgs/markdown/lib/src/inline_syntaxes/escape_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/escape_syntax.dart index c112d930f..53b174875 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/escape_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/escape_syntax.dart @@ -15,7 +15,7 @@ import 'inline_syntax.dart'; // See https://spec.commonmark.org/0.30/#backslash-escapes. class EscapeSyntax extends InlineSyntax { EscapeSyntax() - : super('\\\\([$asciiPunctuationEscaped])', startCharacter: $backslash); + : super('\\\\([$asciiPunctuationEscaped])', startCharacter: $backslash); @override bool onMatch(InlineParser parser, Match match) { diff --git a/pkgs/markdown/lib/src/inline_syntaxes/footnote_ref_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/footnote_ref_syntax.dart index c5d4ef6d6..7cf69e191 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/footnote_ref_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/footnote_ref_syntax.dart @@ -34,8 +34,10 @@ class FootnoteRefSyntax { final key = _footnoteLabel(text); final refs = parser.document.footnoteReferences; // `label` is what footnoteReferences stored, it is case sensitive. - final label = - refs.keys.firstWhere((k) => k.toLowerCase() == key, orElse: () => ''); + final label = refs.keys.firstWhere( + (k) => k.toLowerCase() == key, + orElse: () => '', + ); // `count != null` means footnote was valid. var count = refs[label]; // And then check if footnote was matched. diff --git a/pkgs/markdown/lib/src/inline_syntaxes/image_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/image_syntax.dart index a8b2c3585..6f2904ef8 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/image_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/image_syntax.dart @@ -11,10 +11,7 @@ import 'link_syntax.dart'; /// `![alternate text][label]`. class ImageSyntax extends LinkSyntax { ImageSyntax({super.linkResolver}) - : super( - pattern: r'!\[', - startCharacter: $exclamation, - ); + : super(pattern: r'!\[', startCharacter: $exclamation); @override Element createNode( diff --git a/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart index 6243b01f8..65bf94071 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart @@ -19,29 +19,26 @@ import '../patterns.dart'; /// TODO(srawlins): improve accuracy while ensuring performance, once /// Markdown benchmarking is more mature. class InlineHtmlSyntax extends TextSyntax { - static const _pattern = '(?:$namedTagDefinition)' + static const _pattern = + '(?:$namedTagDefinition)' // Or '|' - // HTML comment, see // https://spec.commonmark.org/0.30/#html-comment. r'