-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upgrade markdown package reference #2364
Changes from 1 commit
6050484
9084683
fddd6dc
95ea5b2
7578b41
a5ae6c2
a1d18d8
5f428bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,12 @@ MutableDocument deserializeMarkdownToDocument( | |
List<ElementToNodeConverter> customElementToNodeConverters = const [], | ||
bool encodeHtml = false, | ||
}) { | ||
final markdownLines = const LineSplitter().convert(markdown); | ||
final markdownLines = const LineSplitter().convert(markdown).map((l) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened to require this difference? I'm not sure what the existing code did, but it's not immediately obvious what the difference is in impact between the original code and this new code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Markdown lib changed from taking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add an explicit type parameter to your map function so that the difference is unambiguous? Part of the confusion here is that reading the code doesn't tell us what type "l" is. |
||
return md.Line(l); | ||
}).toList(); | ||
|
||
final markdownDoc = md.Document( | ||
encodeHtml: encodeHtml, | ||
blockSyntaxes: [ | ||
...customBlockSyntax, | ||
if (syntax == MarkdownSyntax.superEditor) ...[ | ||
|
@@ -519,22 +522,26 @@ abstract class ElementToNodeConverter { | |
DocumentNode? handleElement(md.Element element); | ||
} | ||
|
||
/// A Markdown [TagSyntax] that matches underline spans of text, which are represented in | ||
/// A Markdown [DelimiterSyntax] that matches underline spans of text, which are represented in | ||
/// Markdown with surrounding `¬` tags, e.g., "this is ¬underline¬ text". | ||
/// | ||
/// This [TagSyntax] produces `Element`s with a `u` tag. | ||
class UnderlineSyntax extends md.TagSyntax { | ||
UnderlineSyntax() : super('¬', requiresDelimiterRun: true, allowIntraWord: true); | ||
/// This [DelimiterSyntax] produces `Element`s with a `u` tag. | ||
class UnderlineSyntax extends md.DelimiterSyntax { | ||
|
||
UnderlineSyntax() : super('¬', requiresDelimiterRun: true, allowIntraWord: true, tags: _tags); | ||
|
||
@override | ||
md.Node? close( | ||
Iterable<md.Node>? close( | ||
md.InlineParser parser, | ||
md.Delimiter opener, | ||
md.Delimiter closer, { | ||
required List<md.Node> Function() getChildren, | ||
required String tag, | ||
}) { | ||
return md.Element('u', getChildren()); | ||
final element = md.Element('u', getChildren()); | ||
return [ element ]; | ||
} | ||
static final _tags = [ md.DelimiterTag("u", 1) ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please declare all static members above all instance members (we probably need to add a lint for that at some point). And can you also add a comment above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required by md.DelimiterSyntax, in theory the constructor takes an optional tags member, but a bug in |
||
} | ||
|
||
/// Parses a paragraph preceded by an alignment token. | ||
|
@@ -548,7 +555,7 @@ class _ParagraphWithAlignmentSyntax extends _EmptyLinePreservingParagraphSyntax | |
|
||
@override | ||
bool canParse(md.BlockParser parser) { | ||
if (!_alignmentNotationPattern.hasMatch(parser.current)) { | ||
if (!_alignmentNotationPattern.hasMatch(parser.current.content)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this a pre-existing error on our part? Should we have been accessing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Markdown lib changed from String to Line which has a content member, so this just redirects to where the string is now. |
||
return false; | ||
} | ||
|
||
|
@@ -564,7 +571,7 @@ class _ParagraphWithAlignmentSyntax extends _EmptyLinePreservingParagraphSyntax | |
/// We found a paragraph alignment token, but the block after the alignment token isn't a paragraph. | ||
/// Therefore, the paragraph alignment token is actually regular content. This parser doesn't need to | ||
/// take any action. | ||
if (_standardNonParagraphBlockSyntaxes.any((syntax) => syntax.pattern.hasMatch(nextLine))) { | ||
if (_standardNonParagraphBlockSyntaxes.any((syntax) => syntax.pattern.hasMatch(nextLine.content))) { | ||
return false; | ||
} | ||
|
||
|
@@ -575,7 +582,7 @@ class _ParagraphWithAlignmentSyntax extends _EmptyLinePreservingParagraphSyntax | |
|
||
@override | ||
md.Node? parse(md.BlockParser parser) { | ||
final match = _alignmentNotationPattern.firstMatch(parser.current); | ||
final match = _alignmentNotationPattern.firstMatch(parser.current.content); | ||
|
||
// We've parsed the alignment token on the current line. We know a paragraph starts on the | ||
// next line. Move the parser to the next line so that we can parse the paragraph. | ||
|
@@ -630,13 +637,13 @@ class _EmptyLinePreservingParagraphSyntax extends md.BlockSyntax { | |
return false; | ||
} | ||
|
||
if (parser.current.isEmpty) { | ||
if (parser.current.content.isEmpty) { | ||
// We consider this input to be a separator between blocks because | ||
// it started with an empty line. We want to parse this input. | ||
return true; | ||
} | ||
|
||
if (_isAtParagraphEnd(parser, ignoreEmptyBlocks: _endsWithHardLineBreak(parser.current))) { | ||
if (_isAtParagraphEnd(parser, ignoreEmptyBlocks: _endsWithHardLineBreak(parser.current.content))) { | ||
// Another parser wants to parse this input. Let the other parser run. | ||
return false; | ||
} | ||
|
@@ -648,12 +655,12 @@ class _EmptyLinePreservingParagraphSyntax extends md.BlockSyntax { | |
@override | ||
md.Node? parse(md.BlockParser parser) { | ||
final childLines = <String>[]; | ||
final startsWithEmptyLine = parser.current.isEmpty; | ||
final startsWithEmptyLine = parser.current.content.isEmpty; | ||
|
||
// A hard line break causes the next line to be treated | ||
// as part of the same paragraph, except if the next line is | ||
// the beginning of another block element. | ||
bool hasHardLineBreak = _endsWithHardLineBreak(parser.current); | ||
bool hasHardLineBreak = _endsWithHardLineBreak(parser.current.content); | ||
|
||
if (startsWithEmptyLine) { | ||
// The parser started at an empty line. | ||
|
@@ -669,7 +676,7 @@ class _EmptyLinePreservingParagraphSyntax extends md.BlockSyntax { | |
return null; | ||
} | ||
|
||
if (!_blankLinePattern.hasMatch(parser.current)) { | ||
if (!_blankLinePattern.hasMatch(parser.current.content)) { | ||
// We found an empty line, but the following line isn't blank. | ||
// As there is no hard line break, the first line is consumed | ||
// as a separator between blocks. | ||
|
@@ -682,7 +689,7 @@ class _EmptyLinePreservingParagraphSyntax extends md.BlockSyntax { | |
childLines.add(''); | ||
|
||
// Check for a hard line break, so we consume the next line if we found one. | ||
hasHardLineBreak = _endsWithHardLineBreak(parser.current); | ||
hasHardLineBreak = _endsWithHardLineBreak(parser.current.content); | ||
parser.advance(); | ||
} | ||
|
||
|
@@ -691,9 +698,9 @@ class _EmptyLinePreservingParagraphSyntax extends md.BlockSyntax { | |
// ends with a hard line break. | ||
while (!_isAtParagraphEnd(parser, ignoreEmptyBlocks: hasHardLineBreak)) { | ||
final currentLine = parser.current; | ||
childLines.add(currentLine); | ||
childLines.add(currentLine.content); | ||
|
||
hasHardLineBreak = _endsWithHardLineBreak(currentLine); | ||
hasHardLineBreak = _endsWithHardLineBreak(currentLine.content); | ||
|
||
parser.advance(); | ||
} | ||
|
@@ -777,7 +784,7 @@ class _TaskSyntax extends md.BlockSyntax { | |
|
||
@override | ||
md.Node? parse(md.BlockParser parser) { | ||
final match = pattern.firstMatch(parser.current); | ||
final match = pattern.firstMatch(parser.current.content); | ||
if (match == null) { | ||
return null; | ||
} | ||
|
@@ -795,8 +802,8 @@ class _TaskSyntax extends md.BlockSyntax { | |
// - find a blank line OR | ||
// - find the start of another block element (including another task) | ||
while (!parser.isDone && | ||
!_blankLinePattern.hasMatch(parser.current) && | ||
!_standardNonParagraphBlockSyntaxes.any((syntax) => syntax.pattern.hasMatch(parser.current))) { | ||
!_blankLinePattern.hasMatch(parser.current.content) && | ||
!_standardNonParagraphBlockSyntaxes.any((syntax) => syntax.pattern.hasMatch(parser.current.content))) { | ||
buffer.write('\n'); | ||
buffer.write(parser.current); | ||
|
||
|
@@ -832,7 +839,7 @@ class _HeaderWithAlignmentSyntax extends md.BlockSyntax { | |
|
||
@override | ||
bool canParse(md.BlockParser parser) { | ||
if (!_alignmentNotationPattern.hasMatch(parser.current)) { | ||
if (!_alignmentNotationPattern.hasMatch(parser.current.content)) { | ||
return false; | ||
} | ||
|
||
|
@@ -846,7 +853,7 @@ class _HeaderWithAlignmentSyntax extends md.BlockSyntax { | |
} | ||
|
||
// Only parse if the next line is header. | ||
if (!_headerSyntax.pattern.hasMatch(nextLine)) { | ||
if (!_headerSyntax.pattern.hasMatch(nextLine.content)) { | ||
return false; | ||
} | ||
|
||
|
@@ -855,7 +862,7 @@ class _HeaderWithAlignmentSyntax extends md.BlockSyntax { | |
|
||
@override | ||
md.Node? parse(md.BlockParser parser) { | ||
final match = _alignmentNotationPattern.firstMatch(parser.current); | ||
final match = _alignmentNotationPattern.firstMatch(parser.current.content); | ||
|
||
// We've parsed the alignment token on the current line. We know a header starts on the | ||
// next line. Move the parser to the next line so that we can parse the header. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like all uses of
_tryCreateReferenceLink()
gets converted to a list. Should we just change that method to returnIterable<md.Node>?
and then continue to return it directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. That would be better.