Skip to content

Add support for the @Image directive #404

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

Conversation

dobromir-hristov
Copy link
Contributor

Bug/issue #, if applicable: 97715120

Summary

Extends support for the @Image directive, by allowing users to add captions to images.

image

It uses the already available InlineImage component, and just extends the Figure logic to wrap, if either an anchor or abstract is present.

Dependencies

DocC PR -

Testing

You can add this RenderJSON piece to the content array of your render json primaryContentSections:

                {
                  "type": "image",
                  "identifier": "reference-for-image",
                  "metadata": {
                    "abstract": [
                      {
                        "type": "text",
                        "text": "Image Caption"
                      }
                    ]
                  }
                }

Or use the attached JSON:

example_image.json.zip

Steps:

  1. Assert the caption is rendered below the image

Checklist

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

  • Added tests
  • Ran npm test, and it succeeded
  • Updated documentation if necessary

…tract, but not anchor. use the `metadata.title` to determine if a figure caption should be above/below the content
Copy link
Contributor

@mportiz08 mportiz08 left a comment

Choose a reason for hiding this comment

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

Tested with the DocC branch and looks good (no actual spec changes needed for the image specifically it seems).

The only potential issue I noticed is that the proposal for this new directive showed examples where the caption text is centered underneath the image as opposed to left aligned as it is now. If we were to support that, we may need to update the directive itself to allow for both alignments (because we already support the left aligned ones for older content).

@dobromir-hristov
Copy link
Contributor Author

The only potential issue I noticed is that the proposal for this new directive showed examples where the caption text is centered underneath the image

That is a great observation Marcus. We can do this actually, because we can assume that captions with titles are always above the figures and left aligned, where as ones without a title are below and centered.

I did the change on the Video PR as I assumed we may just use that one, since docc also combined the two features into one - 6c58c84

@dobromir-hristov
Copy link
Contributor Author

@swift-ci test

@dobromir-hristov dobromir-hristov merged commit 7821ca6 into swiftlang:main Sep 15, 2022
@dobromir-hristov dobromir-hristov deleted the dhristov/r97715120-support-figcaption-position branch September 15, 2022 06:49
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 30, 2022
Adds support for using the `@Image` and `@Video` directives from Tutorials
in regular reference documentation. This allows authors to
insert videos into documentation and to create images that have
attached captions.

To that point, the `@Image` and `@Video` directives can now contain
inline text to form a caption.

The final change here is that the `@Video` directive now supports
alt text.

Examples:

    @image(
        source: "overview-hero.png",
        alt: "An illustration of a sleeping sloth."
    ) {
        This is a caption adding additional context for the image.
    }

    @video(
        source: "sloth-smiling.mp4",
        poster: "happy-sloth-frame.png",
        alt: "A short video of a sloth jumping down from a branch.”
    ) {
        A *happy* sloth. 🦥
    }

This change is described on the Swift forums here:
https://forums.swift.org/t/supporting-more-dynamic-content-in-swift-docc-reference-documentation/59527#image-1

Dependencies:

- swiftlang/swift-docc-render#407
- swiftlang/swift-docc-render#404

Resolves rdar://97739628
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 30, 2022
Adds support for using the `@Image` and `@Video` directives from Tutorials
in regular reference documentation. This allows authors to
insert videos into documentation and to create images that have
attached captions.

To that point, the `@Image` and `@Video` directives can now contain
inline text to form a caption.

The final change here is that the `@Video` directive now supports
alt text.

Examples:

    @image(
        source: "overview-hero.png",
        alt: "An illustration of a sleeping sloth."
    ) {
        This is a caption adding additional context for the image.
    }

    @video(
        source: "sloth-smiling.mp4",
        poster: "happy-sloth-frame.png",
        alt: "A short video of a sloth jumping down from a branch.”
    ) {
        A *happy* sloth. 🦥
    }

This change is described on the Swift forums here:
https://forums.swift.org/t/supporting-more-dynamic-content-in-swift-docc-reference-documentation/59527#image-1

Dependencies:

- swiftlang/swift-docc-render#407
- swiftlang/swift-docc-render#404

Resolves rdar://97739628
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Oct 1, 2022
Adds support for using the `@Image` and `@Video` directives from Tutorials
in regular reference documentation. This allows authors to
insert videos into documentation and to create images that have
attached captions.

To that point, the `@Image` and `@Video` directives can now contain
inline text to form a caption.

The final change here is that the `@Video` directive now supports
alt text.

Examples:

    @image(source: "overview-hero.png",
           alt: "An illustration of a sleeping sloth.") {
        This is a caption adding additional context for the image.
    }

    @video(source: "sloth-smiling.mp4",
           poster: "happy-sloth-frame.png",
           alt: "A short video of a sloth jumping down from a branch.") {
        A *happy* sloth. 🦥
    }

This change is described on the Swift forums here:
https://forums.swift.org/t/supporting-more-dynamic-content-in-swift-docc-reference-documentation/59527#image-1

Dependencies:

- swiftlang/swift-docc-render#407
- swiftlang/swift-docc-render#404

Resolves rdar://97739628
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Oct 3, 2022
Adds support for using the `@Image` and `@Video` directives from Tutorials
in regular reference documentation. This allows authors to
insert videos into documentation and to create images that have
attached captions.

To that point, the `@Image` and `@Video` directives can now contain
inline text to form a caption.

The final change here is that the `@Video` directive now supports
alt text.

Examples:

    @image(source: "overview-hero.png",
           alt: "An illustration of a sleeping sloth.") {
        This is a caption adding additional context for the image.
    }

    @video(source: "sloth-smiling.mp4",
           poster: "happy-sloth-frame.png",
           alt: "A short video of a sloth jumping down from a branch.") {
        A *happy* sloth. 🦥
    }

This change is described on the Swift forums here:
https://forums.swift.org/t/supporting-more-dynamic-content-in-swift-docc-reference-documentation/59527#image-1

Dependencies:

- swiftlang/swift-docc-render#407
- swiftlang/swift-docc-render#404

Resolves rdar://97739628
ethan-kusters added a commit to swiftlang/swift-docc that referenced this pull request Oct 3, 2022
Adds support for using the `@Image` and `@Video` directives from Tutorials
in regular reference documentation. This allows authors to
insert videos into documentation and to create images that have
attached captions.

To that point, the `@Image` and `@Video` directives can now contain
inline text to form a caption.

The final change here is that the `@Video` directive now supports
alt text.

Examples:

    @image(source: "overview-hero.png",
           alt: "An illustration of a sleeping sloth.") {
        This is a caption adding additional context for the image.
    }

    @video(source: "sloth-smiling.mp4",
           poster: "happy-sloth-frame.png",
           alt: "A short video of a sloth jumping down from a branch.") {
        A *happy* sloth. 🦥
    }

This change is described on the Swift forums here:
https://forums.swift.org/t/supporting-more-dynamic-content-in-swift-docc-reference-documentation/59527#image-1

Dependencies:

- swiftlang/swift-docc-render#407
- swiftlang/swift-docc-render#404

Resolves rdar://97739628
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.

2 participants