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 a "parameters" section 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

Copy link
Member

@heckj heckj left a comment

Choose a reason for hiding this comment

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

request for some minor wording changes and typo fixes

Question, but not blocking - when does the renderer lean into the concise mode that reduces the output? I know this is part of the bigger plan, but I'm not quite seeing when and why we want to do this from the smaller PRs It seems related to if we want to link into it, but I wasn't entirely sure.

var items = _singleLanguageParameterItems(primary.parameters)

// Find all the inserted and deleted parameters.
// This assumes that parameters appear in the same _order_ in each language representation, which is true in practice.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a debug assertion to check this order? Or just sort them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be a bit long, but doable, to fit the order check inside of the assert call so that it doesn't get evaluated in release builds.

For example, consider these two lists of parameter names that are in order with a few language specific parameters ("A" and "B"):

One  A  Two     Three
One     Two  B  Three

An implementation that checks the order could either:

  • manually iterate each list in parallel so that it can advance one but not the other to skip past language specific parameters in either list
  • iterate through one of the lists, check if the other contains that parameter name, and then check if it contains all the parameters before that and verify that index(of: current) is greater than all index(of: earlier).
  • shrink two subsequences from the start to verify that the first element that exist in both is the same, then shrink the subsequence to after that element and repeat until one of the sub sequences is empty.

In either case, the check would be so long that it's best to write it as either an inline closure or as a private function that only the assert calls.

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist
Copy link
Contributor Author

when does the renderer lean into the concise mode that reduces the output? I know this is part of the bigger plan, but I'm not quite seeing when and why we want to do this from the smaller PRs It seems related to if we want to link into it, but I wasn't entirely sure.

The current answer is "always". You can see here in the draft integration code that DocC always creates a renderer with a conciseness goal.

The reason for this is that the "rich" output is primarily intended to be read by people (with individual tokens in the declaration that can be syntax highlighted and nice word wraps for long symbol names) whereas the purpose so far of adding this content inside each HTML page is for it to be primarily be read by tools such as SEO indexers and LLMs who visit the pages without JavaScript enabled.

In my original proof of concept implementation, the "rich" output existed before the "concise" output and I personally feel that it plays a part in many possible future directions—such as ePub output and maybe some day fully static HTML output without a web app—that it was worth keeping it in the code base as a building block for other changes. That said, the DocC team talked about it offline and concluded that the "rich" specific code paths was a single digit percentage of the overall code and tests with a majority of code being shared.

I'm hoping to have a pitch that I can post in the forums either today or early next week that will describe the bigger plan—primarily short term but also some of the future directions.

@d-ronnqvist d-ronnqvist merged commit 2a1a7bd into swiftlang:main Dec 5, 2025
2 checks passed
@d-ronnqvist d-ronnqvist deleted the output-html-parameters branch December 5, 2025 13:35
d-ronnqvist added a commit to d-ronnqvist/swift-docc that referenced this pull request Dec 17, 2025
…ftlang#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>
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