Skip to content

Conversation

@d-ronnqvist
Copy link
Contributor

Bug/issue #, if applicable: rdar://163326857

Summary

This is another slice of #1366

It adds a helper function to the DocCHTML/MarkdownRenderer to render "topics" and "see also" sections as HTML.

Dependencies

None.

Testing

Nothing in particular for this PR. It only adds an internal helper function. See #1366 for how it eventually does get used.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • Updated documentation if necessary

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test


/// Creates a grouped section with a given name, for example "topics" or "see also" that describes and organizes groups of related API.
///
/// If each language representation of the API has their own language-specific parameters, pass each language representation's parameter information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// If each language representation of the API has their own language-specific parameters, pass each language representation's parameter information.
/// If each language representation of the API has their own language-specific set of parameters, pass the parameter information for each language representation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And: has their -> has its

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2931e98

/// If each language representation of the API has their own language-specific parameters, pass each language representation's parameter information.
///
/// If the API has the _same_ parameters in all language representations, only pass the parameters for one language.
/// This produces a "parameters" section that doesn't hide any parameters for any of the languages (same as if the symbol only had one language representation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This produces a "parameters" section that doesn't hide any parameters for any of the languages (same as if the symbol only had one language representation)
/// This produces a "parameters" section that doesn't hide any parameters for any of the languages (the same as if the symbol only had one language representation).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2931e98


let renderer = makeRenderer(goal: goal, elementsToReturn: elements)
let expectedSectionID = expectedGroupTitle.replacingOccurrences(of: " ", with: "-")
let groupedSection = renderer.groupedSection(named: expectedGroupTitle, groups: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've included the OCC representation with alternate parameters above, could we also include (or make a second set of asserts) that show the expected output when the language is ObjC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What language is specified here doesn't impact the output. This is testing the same task groups in all languages but the names/subheadings of referenced symbols have difference names in each language. You can see in the "rich" test assertion that the the output contains both titles as <code class="swift-only"> and <code class="occ-only"> elements inside the same anchor.

///
/// If the API has the _same_ parameters in all language representations, only pass the parameters for one language.
/// This produces a "parameters" section that doesn't hide any parameters for any of the languages (same as if the symbol only had one language representation)
func groupedSection(named sectionName: String, groups taskGroups: [SourceLanguage: [TaskGroupInfo]]) -> [XMLNode] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments above are talking about a parameters section. Should we update the comments to describe the task group section this function returns?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I updated these comments in 2931e98

let fragmentsByLanguage = RenderHelpers.sortedLanguageSpecificValues(fragmentsByLanguage)
items = if fragmentsByLanguage.count == 1 {
[ _symbolSubheading(fragmentsByLanguage.first!.value, languageFilter: nil) ]
} else if goal == .conciseness, let fragments = fragmentsByLanguage.first?.value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we ignoring the second (and subsequent languages) here for concise mode? Please explain why with a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a short comment that describes this in 2931e98

])
}

private func _symbolSubheading(_ fragments: [LinkedElement.SymbolNameFragment], languageFilter: SourceLanguage?) -> XMLElement {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An HTML example here or above might be nice; this is getting a bit complex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added two examples of this in 2931e98

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist merged commit 30a5e34 into swiftlang:main Dec 9, 2025
2 checks passed
@d-ronnqvist d-ronnqvist deleted the output-html-topics branch December 9, 2025 15:31
d-ronnqvist added a commit to d-ronnqvist/swift-docc that referenced this pull request Dec 17, 2025
…wiftlang#1382)

* Add a helper function for rendering a Topics/SeeAlso section as HTML

rdar://163326857

* Add more code comments and internal documentation comments

* Very slightly correct the test data
d-ronnqvist added a commit that referenced this pull request Dec 17, 2025
…1402)

* Add a new target for rendering Markdown content into static HTML (#1369)

* Add a new target for rendering content into static HTML

rdar://163326857

* Include documentation comments with examples for the various `visit(_:)` methods.

* Document what a `LinkedAsset` represents

* Add code comments to explain how the inline HTML markup is parsed

* Don't lowercase anchors for self-referencing headings

* Avoid nested scopes when switching over names

* Add a code comment about what an "autolink" is

* Add a helper function for rendering availability information as HTML (#1376)

rdar://163326857

* Add a helper function for rendering page breadcrumbs as HTML (#1378)

* Add a helper function for rendering page breadcrumbs as HTML

rdar://163326857

* Apply wording suggestion in documentation comment

Co-authored-by: Joseph Heck <j_heck@apple.com>

---------

Co-authored-by: Joseph Heck <j_heck@apple.com>

* Add a helper function for rendering a parameters section as HTML (#1377)

* Add a helper function for rendering a parameters section as HTML

rdar://163326857

* Apply wording suggestions in documentation comments

Co-authored-by: Pat Shaughnessy <pat_shaughnessy@apple.com>
Co-authored-by: Joseph Heck <j_heck@apple.com>

* Add TODO comment about a debug assertion for the parameter name order

---------

Co-authored-by: Pat Shaughnessy <pat_shaughnessy@apple.com>
Co-authored-by: Joseph Heck <j_heck@apple.com>

* Add tests for parsing of inline HTML when rendering markdown as HTML (#1379)

* Add test about parsing inline HTML except for comments

* Extract inner HTML parsing code into a private function

* Fix minor spelling in code comment

Co-authored-by: Pat Shaughnessy <pat_shaughnessy@apple.com>

---------

Co-authored-by: Pat Shaughnessy <pat_shaughnessy@apple.com>

* Add a helper function for rendering a returns sections as HTML (#1381)

* Add a helper function for rendering a returns sections as HTML

rdar://163326857

* Minor phrasing updates to the parameter section helper's documentation

* Add new source file to Windows CMake file list

* Correct grammar in documentation comments

Co-authored-by: Pat Shaughnessy <pat_shaughnessy@apple.com>

---------

Co-authored-by: Pat Shaughnessy <pat_shaughnessy@apple.com>

* Add a helper function for rendering symbol declarations as HTML (#1384)

* Add a helper function for rendering symbol declarations as HTML

rdar://163326857

* Add code comments to describe why the concise declaration:
  - Only includes the primary language
  - Joins the declaration fragments into a single string

* Add a helper function for rendering a Topics/SeeAlso section as HTML (#1382)

* Add a helper function for rendering a Topics/SeeAlso section as HTML

rdar://163326857

* Add more code comments and internal documentation comments

* Very slightly correct the test data

* Minimally integrate per-page HTML content into each "index.html" file (#1383)

* Minimally integrate per-page HTML content into each "index.html" file

rdar://163326857

* Extract some common code into private helpers

* Move a few common checks into the new private helpers

* Add a helper function for rendering a discussion section as HTML (#1388)

* Add a helper function for rendering a discussion section as HTML

rdar://163326857

* Integrate the discussion section in the HTML renderer

* Include Mentioned In and Relationships sections in the HTML output (#1391)

* Include more content in the HTML output (#1390)

* Include more page content in the HTML output

* Also add deprecation summaries to the HTML output

---------

Co-authored-by: Joseph Heck <j_heck@apple.com>
Co-authored-by: Pat Shaughnessy <pat_shaughnessy@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants