-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add snippet support #61
Conversation
@franklinsch How would you like this tested? |
@bitjammer What do you think about the following:
|
550c0f0
to
4eaabc1
Compare
Tests added. |
4eaabc1
to
de7a096
Compare
@swift-ci Please test |
@swift-ci Please test Linux Platform |
de7a096
to
eb3aa49
Compare
eb3aa49
to
2d238c5
Compare
@swift-ci Please test |
2d238c5
to
ece172e
Compare
Not sure if this repo supports building with other PRs – it needs apple/swift-docc-symbolkit#15. Temporarily edited Package.{swift,resolved} for the time being. |
@swift-ci Please test |
|
ece172e
to
9f7a87e
Compare
@swift-ci Please test |
@swift-ci Please test macOS Platform |
Okay @franklinsch ready for review when you have a moment. Thanks! |
@swift-ci Please test |
guard !context.onlyHasSnippetRelatedChildren(for: documentationNode.reference), | ||
documentationNode.kind != .snippet, | ||
documentationNode.kind != .snippetGroup else { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since knownPages
already filter out pages with only snippet related content, would it make sense to fail the test if there's an unexpected snippet page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snippets don’t get their own page but are in the topic graph (for linking), so the fake module page would be empty. That knownPages filter is to keep those empty module topics from getting registered as a top level page. So snippets are expected in this test.
return [] | ||
} | ||
|
||
let docCommentContent = snippetEntity.markup.children.flatMap { self.visit($0) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have I understood correctly that this comes from the snippet's doc comment? If so, does that mean that snippets support styled inline content (e.g. strong and emphasis)?
If that's supported, would it be worth adding some styling to the test data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, you can write styled markdown in those comments. I'm not convinced that it needs its own test case since it's just a call to visit
and those methods are already tested independently, but let me know if you feel strongly about it.
var elements = [RenderContent]() | ||
|
||
if let chunkName = chunk.name { | ||
elements.append(RenderBlockContent.paragraph(inlineContent: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code path isn't taken in the tests. I think that it'd be good to add a name to the snippet in the test data to be able to assert that that content is processed as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside, chunk names aren't yet authorable but I can add some more test cases once that's implemented on the SwiftPM side if that's all right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. The Test Bundle displays the snipped like how I would expect.
I left two comments about potential cases that could also be tested but I don't feel that either of those is a required changes.
8cb0fd7
to
72cf9b8
Compare
Updated the Package.resolved now that I've merged apple/swift-docc-symbolkit#15. @swift-ci Please test |
- Add a `@Snippet` block directive that takes one argument: the path to the snippet as if it were a symbol link. - Render a snippet as follows: - The snippet explanation - For each snippet chunk: - The name in bold if present - The source code as a code block Snippets do not have their own dedicated page as they won't have accompanying long-form content. Snippets may be collected in a snippet "index" where one can easily search or browse for them in one place, where they'll be grouped appropriately.
72cf9b8
to
d395f71
Compare
@swift-ci Please test |
Add snippet support
@Snippet
block directive that takes one argument: the pathto the snippet as if it were a symbol link.
Snippets are transmitted to DocC via the Symbol Graph format.
Snippets do not have their own dedicated page as they won't have accompanying
long-form content. Snippets may be collected in a snippet "index" where one can
easily search or browse for them in one place, where they'll be grouped
appropriately.
This requires apple/swift-docc-symbolkit#10 (now merged)
This also requires apple/swift-docc-symbolkit#15.