Hi all!
I’m excited to pitch an additional directive to enhance Swift-DocC’s support for more book-like, prose content. For additional context on the related directives that have been introduced over the last couple months, I recommend reading Supporting more types of documentation with Swift-DocC.
Today, Swift-DocC requires every page to include a subheading as the first item in the primary part of the page. This is largely a holdover from how Quick Help in Swift has always worked: if an explicit subheading is omitted, the second paragraph in a documentation comment is automatically converted into an “Overview” section with an Overview subheading. This behavior doesn’t always make sense in more prose-like, article content so I’d like to introduce an option directive to opt-out of this behavior.
I think this directive will also help in migrating existing markdown content to Swift-DocC since this is one of the more surprising behaviors Swift-DocC has. Not all markdown documents are written with the assumption that they will begin with a subheading like this – the ability to disable this behavior at a global level will lower the barrier to entry for moving existing content over to Swift-DocC.
@AutomaticSubheading
@AutomaticSubheading
is a new option directive for customizing the way a page’s subheading is autogenerated.
@AutomaticSubheading
accepts an unnamed parameter containing one of the following:
-
enabled
: A subheading will be auto-generated for the page, following Swift-DocC’s current default behavior.Today, this means that (in the absence of some other H2 heading below the summary sentence) an “Overview” subheading will be created for most pages and a “Discussion” subheading will be created for non-container symbols, like methods. The specifics of this behavior could change in the future; using
enabled
is just a way to opt-in to Swift-DocC’s default and allows for setting a global setting ofdisabled
while still enabling the feature on certain pages. -
disabled
: A subheading will not be auto-generated for the page. To include a subheading, the author can explicitly write one.
@Options(scope: global) {
@AutomaticSubheading(disabled)
}
Examples
``SlothCreator``
Catalog sloths you find in nature and create new adorable virtual sloths.
@Options {
@AutomaticSubheading(disabled)
}
SlothCreator provides models and utilities for creating, tracking,
and caring for sloths. The framework...
...
Future Directions
In the future, we could imagine different behaviors of automatic subheading generation. This could be supported with an additional behavior
parameter. For example, if we wanted to allow for tweaking automatic subheading generation to include the second paragraph of content, instead of the first paragraph:
@AutomaticSubheading(enabled, behavior: secondParagraph)
Additionally, we might want to support customization of the heading that’s used. Maybe “Summary” is a better fit than “Overview” for some collections of documentation:
@AutomaticSubheading(enabled, custom: "Summary")
The specifics of these parameters can be left to a future pitch, I’m just listing them here to show that the first parameter of enabled/disabled
does not restrict the future expansion of this directive.
I'm looking forward to your feedback on the naming and behavior of this new directive.
- Ethan