diff --git a/lib/src/markdown_processor.dart b/lib/src/markdown_processor.dart index e6405aafeb..640ce308e9 100644 --- a/lib/src/markdown_processor.dart +++ b/lib/src/markdown_processor.dart @@ -314,15 +314,12 @@ class MarkdownDocument extends md.Document { var textContent = _htmlEscape.convert(referenceText); var linkedElement = result.commentReferable; if (linkedElement != null) { - if (linkedElement.href != null) { + if (linkedElement.href case var href?) { var anchor = md.Element.text('a', textContent); if (linkedElement is ModelElement && linkedElement.isDeprecated) { anchor.attributes['class'] = 'deprecated'; } - var href = linkedElement.href; - if (href != null) { - anchor.attributes['href'] = href; - } + anchor.attributes['href'] = href; return anchor; } else { // Otherwise this would be `linkedElement.linkedName`, but link bodies diff --git a/lib/src/model/category.dart b/lib/src/model/category.dart index e6383df1db..dc9e49f937 100644 --- a/lib/src/model/category.dart +++ b/lib/src/model/category.dart @@ -143,6 +143,11 @@ class Category String get linkedName { final unbrokenName = name.replaceAll(' ', ' '); if (isDocumented) { + final href = this.href; + if (href == null) { + throw StateError("Requesting the 'linkedName' of a non-canonical " + "category: '$name'"); + } return '$unbrokenName'; } else { return unbrokenName; diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index 58d557ca7c..e62328937c 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -687,6 +687,7 @@ abstract class ModelElement element.kind == ElementKind.NEVER || this is ModelFunction); + final href = this.href; if (href == null) { if (isPublicAndPackageDocumented) { warn(PackageWarning.noCanonicalFound);