Make the fields in Document read-only
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index 5e9be55..bff8268 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md
@@ -4,6 +4,7 @@ the `Document` field, `refLinks`, has been renamed `linkReferences`. * **Breaking change:** Remove the deprecated `ExtensionSet.gitHub` field. Use `ExtensionSet.gitHubFlavored` instead. +* **Breaking change:** Make all of the fields on `Document` read-only. * Overhaul support for emphasis (`*foo*` and `_foo_`) and strong emphasis (`**foo**` and `__foo__`), dramatically improving CommonMark compliance. * Improve support for tab characters, and horizontal rules.
diff --git a/pkgs/markdown/lib/src/document.dart b/pkgs/markdown/lib/src/document.dart index eb7afd6..7aee5da 100644 --- a/pkgs/markdown/lib/src/document.dart +++ b/pkgs/markdown/lib/src/document.dart
@@ -9,24 +9,27 @@ /// Maintains the context needed to parse a Markdown document. class Document { - final Map<String, LinkReference> linkReferences = {}; - Iterable<BlockSyntax> blockSyntaxes; - Iterable<InlineSyntax> inlineSyntaxes; - ExtensionSet extensionSet; - Resolver linkResolver; - Resolver imageLinkResolver; + final Map<String, LinkReference> linkReferences = <String, LinkReference>{}; + final ExtensionSet extensionSet; + final Resolver linkResolver; + final Resolver imageLinkResolver; + final _blockSyntaxes = new Set<BlockSyntax>(); + final _inlineSyntaxes = new Set<InlineSyntax>(); + + Iterable<BlockSyntax> get blockSyntaxes => _blockSyntaxes; + Iterable<InlineSyntax> get inlineSyntaxes => _inlineSyntaxes; Document( {Iterable<BlockSyntax> blockSyntaxes, Iterable<InlineSyntax> inlineSyntaxes, ExtensionSet extensionSet, this.linkResolver, - this.imageLinkResolver}) { - this.extensionSet = extensionSet ?? ExtensionSet.commonMark; - this.blockSyntaxes = new Set() + this.imageLinkResolver}) + : this.extensionSet = extensionSet ?? ExtensionSet.commonMark { + this._blockSyntaxes ..addAll(blockSyntaxes ?? []) ..addAll(this.extensionSet.blockSyntaxes); - this.inlineSyntaxes = new Set() + this._inlineSyntaxes ..addAll(inlineSyntaxes ?? []) ..addAll(this.extensionSet.inlineSyntaxes); }