Skip to content

Commit 1663871

Browse files
committed
remove capitalization from extract tag
1 parent 1e059be commit 1663871

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

Sources/SwiftDocC/Model/Rendering/RenderSectionTranslator/DiscussionSectionTranslator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct DiscussionSectionTranslator: RenderSectionTranslator {
2727
return nil
2828
}
2929

30+
let capitalizedDiscussionContent = [discussionContent[0].withFirstWordCapitalized] + discussionContent[1...]
31+
3032
let title: String?
3133
if let first = discussionContent.first, case RenderBlockContent.heading = first {
3234
// There's already an authored heading. Don't add another heading.
@@ -42,7 +44,7 @@ struct DiscussionSectionTranslator: RenderSectionTranslator {
4244
}
4345
}
4446

45-
return ContentRenderSection(kind: .content, content: discussionContent, heading: title)
47+
return ContentRenderSection(kind: .content, content: capitalizedDiscussionContent, heading: title)
4648
}
4749
}
4850
}

Sources/SwiftDocC/Model/Rendering/RenderSectionTranslator/ReturnsSectionTranslator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ struct ReturnsSectionTranslator: RenderSectionTranslator {
2828
return nil
2929
}
3030

31-
return ContentRenderSection(kind: .content, content: returnsContent, heading: "Return Value")
31+
let capitalizedReturnsContent = [returnsContent[0].withFirstWordCapitalized] + returnsContent[1...]
32+
33+
return ContentRenderSection(kind: .content, content: capitalizedReturnsContent, heading: "Return Value")
3234
}
3335
}
3436
}

Sources/SwiftDocC/Utility/MarkupExtensions/ListItemExtractor.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ extension ListItem {
152152
if dropTag {
153153
newText = String(text.string.dropFirst(text.string.count - trimmedText.count + tag.count).drop(while: { $0 == " " }))
154154
}
155-
return [Text(newText.capitalizeFirstWord())] + Array(firstParagraph.inlineChildren.dropFirst(1))
155+
156+
return [Text(newText)] + Array(firstParagraph.inlineChildren.dropFirst(1))
156157
}
157158

158159
return nil

Tests/SwiftDocCTests/Infrastructure/AutoCapitalizationTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,32 @@ class AutoCapitalizationTests: XCTestCase {
159159
[SwiftDocC.RenderBlockContent.paragraph(SwiftDocC.RenderBlockContent.Paragraph(inlineContent: [SwiftDocC.RenderInlineContent.text("a`nother invalid capitalization")]))]])
160160
}
161161

162+
func testReturnsCapitalization() throws {
163+
let symbolGraph = makeSymbolGraph(docComment: """
164+
Some symbol description.
165+
166+
- Returns: string, first word should have been capitalized here.
167+
""")
168+
169+
let url = try createTempFolder(content: [
170+
Folder(name: "unit-test.docc", content: [
171+
JSONFile(name: "ModuleName.symbols.json", content: symbolGraph)
172+
])
173+
])
174+
let (_, bundle, context) = try loadBundle(from: url)
175+
176+
XCTAssertEqual(context.problems.count, 0)
177+
178+
let reference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/ModuleName/functionName(...)", sourceLanguage: .swift)
179+
let node = try context.entity(with: reference)
180+
let symbol = try XCTUnwrap(node.semantic as? Symbol)
181+
182+
let returnsSectionTranslator = ReturnsSectionTranslator()
183+
var renderNodeTranslator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference, source: url)
184+
var renderNode = renderNodeTranslator.visit(symbol) as! RenderNode
185+
let translatedReturns = returnsSectionTranslator.translateSection(for: symbol, renderNode: &renderNode, renderNodeTranslator: &renderNodeTranslator)
186+
let returnsRenderSection = translatedReturns?.defaultValue?.section as! ContentRenderSection
187+
188+
XCTAssertEqual(returnsRenderSection.content, [SwiftDocC.RenderBlockContent.heading(SwiftDocC.RenderBlockContent.Heading(level: 2, text: "Return Value", anchor: Optional("return-value"))), SwiftDocC.RenderBlockContent.paragraph(SwiftDocC.RenderBlockContent.Paragraph(inlineContent: [SwiftDocC.RenderInlineContent.text("String, first word should have been capitalized here.")]))])
189+
}
162190
}

0 commit comments

Comments
 (0)