Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pkgs/markdown/lib/src/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,12 @@ class Document {

if (footnotes.isNotEmpty) {
// Sort footnotes by appearing order.
final ordinal = {
for (var i = 0; i < footnoteLabels.length; i++) footnoteLabels[i]: i,
};
footnotes.sort((l, r) {
// HTML IDs are URI-encoded, but the reference order uses raw labels.
final labelL = l.footnoteLabel?.toLowerCase();
final labelR = r.footnoteLabel?.toLowerCase();
return (ordinal[labelL] ?? 0) - (ordinal[labelR] ?? 0);
return (_footnoteLabelIndex[labelL] ?? 0) -
(_footnoteLabelIndex[labelR] ?? 0);
});
final list = Element('ol', <Node>[...footnotes]);

Expand Down
24 changes: 20 additions & 4 deletions pkgs/markdown/lib/src/inline_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ class InlineParser {
}
}

static final Set<InlineSyntax> _builtInSyntaxes = {
...ExtensionSet.gitHubWeb.inlineSyntaxes,
...ExtensionSet.gitHubFlavored.inlineSyntaxes,
...ExtensionSet.commonMark.inlineSyntaxes,
};

static bool _isBuiltInExtension(InlineSyntax syntax) =>
ExtensionSet.gitHubWeb.inlineSyntaxes.contains(syntax) ||
ExtensionSet.gitHubFlavored.inlineSyntaxes.contains(syntax) ||
ExtensionSet.commonMark.inlineSyntaxes.contains(syntax);
_builtInSyntaxes.contains(syntax);

List<Node> parse() {
while (!isDone) {
Expand Down Expand Up @@ -484,7 +488,19 @@ class _PlainTextSyntax extends TextSyntax {
final bool _allowSpaces;
final bool _includeHebrew;

_PlainTextSyntax({required bool allowSpaces, required bool includeHebrew})
// The syntax is stateless, so one instance per configuration is shared to
// avoid compiling its pattern for every parser.
static final _instances = <(bool, bool), _PlainTextSyntax>{};

factory _PlainTextSyntax({
required bool allowSpaces,
required bool includeHebrew,
}) => _instances.putIfAbsent((
allowSpaces,
includeHebrew,
), () => _PlainTextSyntax._(allowSpaces, includeHebrew));

_PlainTextSyntax._(bool allowSpaces, bool includeHebrew)
: _allowSpaces = allowSpaces,
_includeHebrew = includeHebrew,
super(_plainTextPattern(allowSpaces, includeHebrew));
Expand Down
Loading