Skip to content

Add syntax highlighting to the code blocks in the markdown returned by SourceKit. #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/SourceKitLSP/Swift/CommentXML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private struct XMLToMarkdown {
switch node.name {
case "Declaration":
newlineIfNeeded(count: 2)
out += "```\n"
out += "```swift\n"
toMarkdown(node.children)
out += "\n```\n\n---\n"

Expand Down Expand Up @@ -125,7 +125,7 @@ private struct XMLToMarkdown {
case "CodeListing":
lineNumber = 0
newlineIfNeeded(count: 2)
out += "```\n"
out += "```\(node.attributes?.first(where: { $0.name == "language" })?.stringValue ?? "")\n"
toMarkdown(node.children, separator: "\n")
out += "```"

Expand Down
26 changes: 13 additions & 13 deletions Tests/SourceKitLSPTests/LocalSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
<Declaration>func foo(_ bar: <Type usr="fake">Baz</Type>)</Declaration>
"""), """
```
```swift
func foo(_ bar: Baz)
```

Expand All @@ -812,7 +812,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
<Declaration>func foo() -&gt; <Type>Bar</Type></Declaration>
"""), """
```
```swift
func foo() -> Bar
```

Expand All @@ -822,7 +822,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
<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>
"""), """
```
```swift
func replacingOccurrences<Target, Replacement>(of target: Target, with replacement: Replacement, options: String.CompareOptions = default, range searchRange: Range<String.Index>? = default) -> String where Target : StringProtocol, Replacement : StringProtocol
```

Expand All @@ -835,7 +835,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
<Class><Declaration>var foo</Declaration></Class>
"""), """
```
```swift
var foo
```

Expand All @@ -846,7 +846,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
<Class><Name>foo</Name><Declaration>var foo</Declaration></Class>
"""), """
```
```swift
var foo
```

Expand All @@ -856,7 +856,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
<Class><USR>asdf</USR><Declaration>var foo</Declaration><Name>foo</Name></Class>
"""), """
```
```swift
var foo
```

Expand All @@ -874,7 +874,7 @@ final class LocalSwiftTests: XCTestCase {
"""), """
FOO

```
```swift
var foo
```

Expand Down Expand Up @@ -1005,7 +1005,7 @@ final class LocalSwiftTests: XCTestCase {
"</CommentParts>" +
"</Class>"
), """
```
```swift
struct String
```

Expand All @@ -1018,14 +1018,14 @@ final class LocalSwiftTests: XCTestCase {

You can create new strings A *string literal* i

```
```swift
1.\tlet greeting = "Welcome!"
2.\t
```

...

```
```swift
1.\tlet greeting = "Welcome!"
2.\t
```
Expand Down Expand Up @@ -1176,7 +1176,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(content.kind, .markdown)
XCTAssertEqual(content.value, """
S
```
```swift
struct S
```

Expand Down Expand Up @@ -1228,7 +1228,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(content.kind, .markdown)
XCTAssertEqual(content.value, ##"""
test(\_:\_:)
```
```swift
func test(_ a: Int, _ b: Int)
```

Expand All @@ -1253,7 +1253,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(content.kind, .markdown)
XCTAssertEqual(content.value, ##"""
\*%\*(\_:\_:)
```
```swift
func *%* (lhs: String, rhs: String)
```

Expand Down