Rename the Link class to LinkReference (dart-lang/markdown#204)
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index dc28e7a..c9d339c 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md
@@ -1,5 +1,7 @@ -## 1.1.2-dev +## 2.0.0-dev +* **Breaking change:** The `Link` class has been renamed `LinkReference`, and + the `Document` field, `refLinks`, has been renamed `linkReferences`. * 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/block_parser.dart b/pkgs/markdown/lib/src/block_parser.dart index f630a92..25d74f8 100644 --- a/pkgs/markdown/lib/src/block_parser.dart +++ b/pkgs/markdown/lib/src/block_parser.dart
@@ -1007,8 +1007,8 @@ // References are case-insensitive. label = label.toLowerCase().trim(); - parser.document.refLinks - .putIfAbsent(label, () => new Link(label, destination, title)); + parser.document.linkReferences + .putIfAbsent(label, () => new LinkReference(label, destination, title)); return true; } }
diff --git a/pkgs/markdown/lib/src/document.dart b/pkgs/markdown/lib/src/document.dart index 7aeb97e..eb7afd6 100644 --- a/pkgs/markdown/lib/src/document.dart +++ b/pkgs/markdown/lib/src/document.dart
@@ -9,7 +9,7 @@ /// Maintains the context needed to parse a Markdown document. class Document { - final Map<String, Link> refLinks = {}; + final Map<String, LinkReference> linkReferences = {}; Iterable<BlockSyntax> blockSyntaxes; Iterable<InlineSyntax> inlineSyntaxes; ExtensionSet extensionSet; @@ -56,9 +56,25 @@ } } -class Link { - final String id; - final String url; +/// A [link reference +/// definition](http://spec.commonmark.org/0.28/#link-reference-definitions). +class LinkReference { + /// The [link label](http://spec.commonmark.org/0.28/#link-label). + /// + /// Temporarily, this class is also being used to represent the link data for + /// an inline link (the destination and title), but this should change before + /// the package is released. + final String label; + + /// The [link destination](http://spec.commonmark.org/0.28/#link-destination). + final String destination; + + /// The [link title](http://spec.commonmark.org/0.28/#link-title). final String title; - Link(this.id, this.url, this.title); + + /// Construct a new [LinkReference], with all necessary fields. + /// + /// If the parsed link reference definition does not include a title, use + /// `null` for the [title] parameter. + LinkReference(this.label, this.destination, this.title); }
diff --git a/pkgs/markdown/lib/src/inline_parser.dart b/pkgs/markdown/lib/src/inline_parser.dart index 060d696..777ba21 100644 --- a/pkgs/markdown/lib/src/inline_parser.dart +++ b/pkgs/markdown/lib/src/inline_parser.dart
@@ -508,7 +508,7 @@ var element = new Element('a', state.children); - element.attributes["href"] = escapeHtml(link.url); + element.attributes["href"] = escapeHtml(link.destination); if (link.title != null) { element.attributes['title'] = escapeHtml(link.title); } @@ -520,7 +520,11 @@ /// /// This method can return null, if the link is a reference link, and has no /// accompanying link reference definition. - Link getLink(InlineParser parser, Match match, TagState state) { + /// + /// Temporarily, this is returning [LinkReference]s, for convenience, which + /// is an improper use of [LinkReference]s. This should change before this + /// package is released. + LinkReference getLink(InlineParser parser, Match match, TagState state) { if (match[3] != null) { // Inline link like [foo](url). var url = match[3]; @@ -531,9 +535,9 @@ url = url.substring(1, url.length - 1); } - return new Link(null, url, title); + return new LinkReference(null, url, title); } else { - String id; + String label; String _contents() { var offset = pattern.pattern.length - 1; return parser.source.substring(state.startPos + offset, parser.pos); @@ -542,18 +546,18 @@ // Reference link like [foo][bar]. if (match[1] == null) { // There are no reference brackets ("shortcut reference link"), so infer - // the id from the contents. - id = _contents(); + // the label from the contents. + label = _contents(); } else if (match[2] == '') { - // The id is empty ("[]") so infer it from the contents. - id = _contents(); + // The label is empty ("[]") so infer it from the contents. + label = _contents(); } else { - id = match[2]; + label = match[2]; } // References are case-insensitive. - id = id.toLowerCase(); - return parser.document.refLinks[id]; + label = label.toLowerCase(); + return parser.document.linkReferences[label]; } } @@ -577,7 +581,7 @@ var link = getLink(parser, match, state); if (link == null) return null; var image = new Element.empty("img"); - image.attributes["src"] = escapeHtml(link.url); + image.attributes["src"] = escapeHtml(link.destination); image.attributes["alt"] = state?.textContent ?? ''; if (link.title != null) {
diff --git a/pkgs/markdown/lib/src/version.dart b/pkgs/markdown/lib/src/version.dart index a4966e3..f3d0d97 100644 --- a/pkgs/markdown/lib/src/version.dart +++ b/pkgs/markdown/lib/src/version.dart
@@ -1,2 +1,2 @@ /// The current version of markdown. -final String version = '1.1.2-dev'; +final String version = '2.0.0-dev';
diff --git a/pkgs/markdown/pubspec.yaml b/pkgs/markdown/pubspec.yaml index 25fa227..b1170fd 100644 --- a/pkgs/markdown/pubspec.yaml +++ b/pkgs/markdown/pubspec.yaml
@@ -1,5 +1,5 @@ name: markdown -version: 1.1.2-dev +version: 2.0.0-dev author: Dart Team <misc@dartlang.org> description: A library for converting markdown to HTML. homepage: https://github.com/dart-lang/markdown