Skip to content
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

Adds an identifier prop to the RichText component for captions, allowing annotation #46917

Merged
merged 2 commits into from
Jan 6, 2023

Conversation

mhkuu
Copy link
Contributor

@mhkuu mhkuu commented Jan 5, 2023

What?

This PR adds an identifier prop to the RichText component for audio, embed, gallery, image, table, and video captions.

Why?

This PR is a follow-up to this older PR. With this PR, we allow to annotate textual content in audio, embed, gallery, image, table, and video captions using the core/annotations store. In Yoast SEO, we use this annotation functionality for our highlighting functionality, e.g., in our keyphrase distribution assessment.

How?

This PR opens up captions to annotation by adding an identifier prop to the RichText component for audio, embed, gallery, image, table, and video captions.

Testing Instructions

  1. Open a new Post.
  2. Insert a paragraph block and an image block.
  3. Add a caption to the image.
  4. Add the text "This is a test for Gutenberg." to the paragraph block, as well as to the image caption.
  5. Add the following code to your console. Replace the blockClientId with the id of the paragraph block (you can find that in the data-block attribute when you inspect the underlying HTML):
wp.data.dispatch( "core/annotations" ).__experimentalAddAnnotation({
  type: 'ANNOTATION_ADD',
  id: 'test',
  blockClientId: 'd10cd677-8236-4e0a-8062-f96e9f17ca2c', // change this!
  richTextIdentifier: 'content',
  source: 'test',
  selector: 'range',
  range: {
    start: 19,
    end: 28
  }
})
  1. Confirm the word "Gutenberg" is marked with yellow in the paragraph block.
  2. Add the following code to your console. Replace the blockClientId with the id of the image caption block:
wp.data.dispatch( "core/annotations" ).__experimentalAddAnnotation({
  type: 'ANNOTATION_ADD',
  id: 'test',
  blockClientId: 'd10cd677-8236-4e0a-8062-f96e9f17ca2c', // change this!
  richTextIdentifier: 'caption',
  source: 'test',
  selector: 'range',
  range: {
    start: 19,
    end: 28
  }
})
  1. Confirm the word "Gutenberg" is marked with yellow in the image caption.
  2. Without this PR, the word "Gutenberg" would be highlighted in the paragraph content, but not in the image caption content.
  3. Repeat the above steps for audio, embed, gallery, table, and video blocks.

Testing Instructions for Keyboard

NA

Screenshots or screencast

NA

@mhkuu mhkuu requested a review from ajitbohra as a code owner January 5, 2023 15:54
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jan 5, 2023
@github-actions
Copy link

github-actions bot commented Jan 5, 2023

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @mhkuu! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

I think we have more blocks with captions: table, gallery, embed. Should we be doing the same there for consistency?

@mhkuu
Copy link
Contributor Author

mhkuu commented Jan 6, 2023

I think that does make sense, good point 👍 I'll look into those and will adapt the PR accordingly.

…lery, and table captions, allowing annotation
@mhkuu mhkuu requested a review from geriux as a code owner January 6, 2023 12:26
@mhkuu mhkuu changed the title Adds an identifier prop to the RichText component for audio, image, and video captions, allowing annotation Adds an identifier prop to the RichText component for captions, allowing annotation Jan 6, 2023
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@youknowriad youknowriad merged commit 126dc2a into WordPress:trunk Jan 6, 2023
@github-actions github-actions bot added this to the Gutenberg 15.0 milestone Jan 6, 2023
@mhkuu mhkuu deleted the add/caption-identifier branch January 6, 2023 13:24
@priethor priethor added the [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable label Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants