Currently, when a developer writes a symbol extension markdown file, and creates a topic section which is named the same as one of the titles which are used for automatic curation ("Initializers", "Instance Properties", "Instance Methods", "Type Aliases", etc.), the result is duplicated sections:
This PR changes this behaviour so that automatically curated section contents are merged with existing sections, if they have the same title:
Implementation
in RenderNodeTranslator.visitSymbol(_:), after the list of automatically curated task groups has been created, we now check whether there is an existing manually curated section with the same title.
If it exists, we extend this section in place with the symbol references from the automatically curated task group. Otherwise, we create a new section same as before.
Dependencies
No dependencies.
Testing
You can use the following test package to test locally:
TestPackage.zip
Steps:
Generate rendered documentation for the test package using docc
Creating an extension markdown file for a package's symbol.
Creating a section under topics which is titled same as one of the titles which are used for automatic curation ("Initializers", "Instance Properties", "Instance Methods", "Type Aliases", etc.).
Render the documentation.
View the extended symbol's documentation, and verify that the contents from the manually curated section have been merged with the automatically curated symbols.
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
[x] Added tests
[x] Ran the ./bin/test script and it succeeded
[x] Updated documentation if necessary
Verification
Unit tests
Added test testAutomaticallyCuratedSymbolTopicsAreMergedWithManuallyCuratedTopics(), which passes. This test explicitly tests the new merging functionality. I'm relying on the existing tests for testing that previous automatic curation functionality still works as expected.
Ran ./bin/test:
=> Checking for unacceptable language… okay.
=> Checking license headers… okay.
=> Validating scripts in bin subdirectory… okay.
Site rendering
Verified manually by creating a test package with an extension markdown file which defines a topic section "Initializers". Before this change, the result would be two separate sections, both titled "Initializers". After this change, there is only one section named "Initializer" with the merged contents.
Input markdown:
# ``ExampleClass``
This is a summary.
## Overview
This is an overview.
## Topics
### Other group
- <doc:ExampleArticle>
### Initializers
- <doc:ExampleArticle>
## See Also
- ``TestPackage``
Before
After
Documentation
As far as I can tell, no changes to the documentation are needed.
Bug/issue #, if applicable: rdar://61899214
Summary
Currently, when a developer writes a symbol extension markdown file, and creates a topic section which is named the same as one of the titles which are used for automatic curation ("Initializers", "Instance Properties", "Instance Methods", "Type Aliases", etc.), the result is duplicated sections:![3cf36344-f5ab-466f-832f-1ffc8c738ac7](https://github.com/apple/swift-docc/assets/15234535/67cd2d8a-4096-4003-8b2f-5439487b1352)
This PR changes this behaviour so that automatically curated section contents are merged with existing sections, if they have the same title:![c0df4dbb-3317-4bf6-a517-ccb8e48dcdff](https://github.com/apple/swift-docc/assets/15234535/159f928f-b69d-4d79-b565-8bb20b79aaca)
Implementation
in
RenderNodeTranslator.visitSymbol(_:)
, after the list of automatically curated task groups has been created, we now check whether there is an existing manually curated section with the same title.If it exists, we extend this section in place with the symbol references from the automatically curated task group. Otherwise, we create a new section same as before.
Dependencies
No dependencies.
Testing
You can use the following test package to test locally: TestPackage.zip
Steps:
docc
ExampleClass
(at http://localhost:8080/documentation/testpackage/exampleclass) and validate that there is only one "Initializers" section under "Topics".More generally, this can be reproduced by:
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeededVerification
Unit tests
Added test
testAutomaticallyCuratedSymbolTopicsAreMergedWithManuallyCuratedTopics()
, which passes. This test explicitly tests the new merging functionality. I'm relying on the existing tests for testing that previous automatic curation functionality still works as expected.Ran
./bin/test
:Site rendering
Verified manually by creating a test package with an extension markdown file which defines a topic section "Initializers". Before this change, the result would be two separate sections, both titled "Initializers". After this change, there is only one section named "Initializer" with the merged contents.
Input markdown:
Documentation
As far as I can tell, no changes to the documentation are needed.