-
Notifications
You must be signed in to change notification settings - Fork 201
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
Create DelimiterSyntax to replace TagSyntax #407
Conversation
And create a new TagSyntax extends from DelimiterSyntax
This is going to need a changelog entry – right? |
Yes |
Because + Intraword emphasis with * is permitted + Intraword emphasis with _ is not permitted
Sorry to keep committing new stuffs to this PR. |
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.
Note that this is a breaking change, even leaving TagSyntax intact: Some fields now return DelimiterSyntax instead of TagSyntax, and StrikethroughSyntax no longer extends TagSyntax.
If you like, you can add a CHANGELOG entry, and bump the major version number in pubspec.yaml and lib/src/version.dart.
lib/src/inline_parser.dart
Outdated
@@ -972,7 +1016,7 @@ class LinkSyntax extends TagSyntax { | |||
@override | |||
Node? close( | |||
InlineParser parser, covariant SimpleDelimiter opener, Delimiter? closer, | |||
{required List<Node> Function() getChildren}) { | |||
{String? tag, required List<Node> Function() getChildren}) { |
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.
Style nit: please add a trailing comma here, so that each parameter appears on its own line.
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.
Fixed
lib/src/inline_parser.dart
Outdated
{required List<Node> Function() getChildren}) { | ||
return Element('del', getChildren()); | ||
} | ||
/// Parses `==mark==` to `<mark>mark</mark>`. |
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.
Can you add some documentation about where this is coming from? We need specifications which we can follow in order to support special syntaxes.
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.
I did not find a common used specification about it.
My idea is all the syntaxes extend DelimiterSyntax
with requiresDelimiterRun = true
follow the commonmark specification of Emphasis and strong emphasis: https://spec.commonmark.org/0.30/#emphasis-and-strong-emphasis
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.
I don't think we can support an unspecified, or loosely specified syntax. Even if it is not a complicated one, it adds maintenance burden, and can create breaking changes when a well-specified, popular syntax does emerge, and is slightly different from what we've implemented. As is noted in the issue, some implementations seem to support different delimiters for highlighting, so I think this is too under-specified to accept.
I'll comment more on the issue.
lib/src/inline_parser.dart
Outdated
/// Create a new [TagSyntax] which matches text on [pattern]. | ||
final List<DelimiterTag>? tags; | ||
|
||
/// Create a new [DelimiterSyntax] which matches text on [pattern]. |
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.
Nit: "Creates" instead of "Create"
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.
Thanks! Fixed
lib/src/inline_parser.dart
Outdated
class DelimiterTag { | ||
DelimiterTag(this.tag, this.indicators); | ||
|
||
// Tag name of AST Element |
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.
Grammar nit: "Tag name of the HTML element." (ending with a period)
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.
Fixed
lib/src/inline_parser.dart
Outdated
final String tag; | ||
|
||
/// The length of [indicators] | ||
final int indicators; |
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.
The name of this field is probably not the best (as seen by the doc comment above it).
I would expect a field named 'indicators' to the String perhaps, or a List. This should be renamed to something like... 'indicatorLength'. If that is too long, I'd be open to other ideas...
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.
I have changed it to indicatorLength. Yes, indicatorLength is too long, this was the reason why I named it indicators.
lib/src/inline_parser.dart
Outdated
{required List<Node> Function() getChildren}) { | ||
var strong = opener.length >= 2 && closer.length >= 2; | ||
return Element(strong ? 'strong' : 'em', getChildren()); | ||
{required String tag, required List<Node> Function() getChildren}) { |
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.
Style nit: please add a trailing comma here, so that each parameter appears on its own line.
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.
Fixed. I thought we prefer to use this no trailing comma style.
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.
I actually don't have a strong preference. Except when we have some long parameters (like with the required keyword), and now they're creeping onto a third line. In the analyzer codebase we've been moving towards using trailing commas more. It's not a hard rule yet.
Done! |
Will we merge this PR? I'm waiting for the merge to continue with other tasks to avoid a lot of conflicts. Thanks! |
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.
I think that DelimiterSyntax is a fine improvement over TagSyntax, and I think we can definitely merge this PR with that feature.
But I don't think the HighlightSyntax should be a part of all this. The DelimiterSyntax definitely makes HighlightSyntax easier, so that others can implement this syntax, and perhaps other extensions for other Markdown flavors.
Thanks! HighlightSyntax has been removed. Yes, I agree, we should only focus on the standard syntaxes / flavors. |
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.
Very nice feature, thanks!
Introduces a new syntax
DelimiterSyntax
which has the same parsing strategy asTagSyntax
, but more flexible.For example:
output:
This PR also add anther syntax
EmphasisSyntax
, which replacesTagSyntax(r'\*+', requiresDelimiterRun: true)
andTagSyntax(r'_+', requiresDelimiterRun: true)