diff options
Diffstat (limited to 'src/Kotlin')
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 5 | ||||
-rw-r--r-- | src/Kotlin/ResolveReferences.kt | 30 |
2 files changed, 13 insertions, 22 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 389b2732..b7290b58 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -53,10 +53,7 @@ public fun MarkdownTree.toContent(): Content { MarkdownElementTypes.LINK -> { val target = findChildByType(node, MarkdownElementTypes.TARGET)?.let { getNodeText(it) } ?: "" val href = findChildByType(node, MarkdownElementTypes.HREF)?.let { getNodeText(it) } - val link = if (href != null) - ContentExternalLink(href) - else - ContentNameLink(target) + val link = if (href != null) ContentExternalLink(href) else ContentExternalLink(target) link.append(ContentText(target)) parent.append(link) } diff --git a/src/Kotlin/ResolveReferences.kt b/src/Kotlin/ResolveReferences.kt index b14d3718..1349c69e 100644 --- a/src/Kotlin/ResolveReferences.kt +++ b/src/Kotlin/ResolveReferences.kt @@ -49,33 +49,27 @@ public fun DocumentationContext.resolveReferences(node: DocumentationNode) { fun DocumentationContext.resolveContentLinks(node: DocumentationNode, content: ContentNode) { val snapshot = content.children.toList() for (child in snapshot) { - val referenceText = when (child) { - is ContentExternalLink -> child.href - is ContentNameLink -> child.name - else -> null - } + if (child is ContentExternalLink) { + val referenceText = child.href + if (Name.isValidIdentifier(referenceText)) { + val scope = getResolutionScope(node) + val symbolName = Name.guess(referenceText) + val symbol = scope.getLocalVariable(symbolName) ?: + scope.getProperties(symbolName).firstOrNull() ?: + scope.getFunctions(symbolName).firstOrNull() ?: + scope.getClassifier(symbolName) - if (referenceText != null && Name.isValidIdentifier(referenceText)) { - val scope = getResolutionScope(node) - val symbolName = Name.guess(referenceText) - val symbol = - scope.getLocalVariable(symbolName) ?: - scope.getProperties(symbolName).firstOrNull() ?: - scope.getFunctions(symbolName).firstOrNull() ?: - scope.getClassifier(symbolName) + if (symbol != null) { + val targetNode = descriptorToNode[symbol] + val contentLink = if (targetNode != null) ContentNodeLink(targetNode) else ContentExternalLink("#") - if (symbol != null) { - val targetNode = descriptorToNode[symbol] - if (targetNode != null) { val index = content.children.indexOf(child) content.children.remove(index) - val contentLink = ContentNodeLink(targetNode) contentLink.children.addAll(child.children) content.children.add(index, contentLink) } } } - resolveContentLinks(node, child) } }
\ No newline at end of file |