Skip to content

Commit 0aad9a9

Browse files
authored
Merge pull request #416 from LebJe/formatLinks
Format Links in the Documentation Markdown from SourceKit
2 parents efb5adf + ed9ac9e commit 0aad9a9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sources/SourceKitLSP/Swift/CommentXML.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ private struct XMLToMarkdown {
157157
toMarkdown(node.children)
158158
out += "\n\n"
159159

160+
case "Link":
161+
if let href = node.attributes?.first(where: { $0.name == "href" })?.stringValue {
162+
out += "["
163+
toMarkdown(node.children)
164+
out += "](\(href))"
165+
} else {
166+
// Not a valid link.
167+
toMarkdown(node.children)
168+
}
169+
160170
default:
161171
toMarkdown(node.children)
162172
}

Tests/SourceKitLSPTests/LocalSwiftTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,16 @@ final class LocalSwiftTests: XCTestCase {
818818
819819
---
820820
821+
""")
822+
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
823+
<Link href="https://example.com">My Link</Link>
824+
"""), """
825+
[My Link](https://example.com)
826+
""")
827+
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
828+
<Link>My Invalid Link</Link>
829+
"""), """
830+
My Invalid Link
821831
""")
822832
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
823833
<Declaration>func replacingOccurrences&lt;Target, Replacement&gt;(of target: Target, with replacement: Replacement, options: <Type usr="s:SS">String</Type>.<Type usr="s:SS10FoundationE14CompareOptionsa">CompareOptions</Type> = default, range searchRange: <Type usr="s:Sn">Range</Type>&lt;<Type usr="s:SS">String</Type>.<Type usr="s:SS5IndexV">Index</Type>&gt;? = default) -&gt; <Type usr="s:SS">String</Type> where Target : <Type usr="s:Sy">StringProtocol</Type>, Replacement : <Type usr="s:Sy">StringProtocol</Type></Declaration>

0 commit comments

Comments
 (0)