API Collection
Documentation Context
Build and query the in-memory documentation model.
Discussion
A documentation context is the the in-memory representation of a “unit” of documentation (for example a module, package, or technology). The context is generally responsible for:
Analyzing bundle file contents and converting to semantic models.
Managing a graph of documentation nodes (a single node representing one documentation topic).
Processing assets like media files or download archives.
Resolving links to external documentation sources via ExternalDocumentationSource and resolving external symbols via GlobalExternalSymbolResolver.
Random access to documentation data including walking the graph and path finding.
Creating a Context
Use init(bundle:dataProvider:diagnosticEngine:configuration:) to create a context for a given bundle:
let inputsProvider = DocumentationContext.InputsProvider()
let (bundle, dataProvider) = try inputsProvider.inputsAndDataProvider(
startingPoint: catalogURL,
options: bundleDiscoveryOptions
)
let context = try DocumentationContext(bundle: bundle, dataProvider: dataProvider)
Accessing Documentation
Use entity(with:) to access a documentation node by its topic reference:
let reference = ResolvedTopicReference(
bundleID: "com.mybundle",
path: "/documentation/ValidationKit/EmailValidator",
fragment: nil,
sourceLanguage: .swift)
let node = try context.entity(with: reference)
To find out the location of the source file for a given documentation node use:
let sourceFileURL = try context.documentURL(for: reference)
Topics
Documentation Context
Documentation Nodes
Rendering URLs
External Documentation Sources
Code Listings