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

Add code block copy button #5334

Merged
merged 37 commits into from
Oct 26, 2024

Conversation

compulim
Copy link
Contributor

@compulim compulim commented Oct 25, 2024

Fixes #

Changelog Entry

Added

Description

For code blocks inside Markdown (via triple-backtick or <pre>), we will add a copy button on the top right corner of it.

image

Design

We are introducing internal-use Web Components.

As we go through sanitization, DOM become string and it lose event handler. In other words, we cannot listen to "click" event on the button after sanitization.

Our solution is to use Web Components so we can preserve logic during sanitization.

Alternatively, we could have a catch-all click handler on Markdown, but it is not trivial as Adaptive Cards requires a HTML string instead of DOM too. That means, we will need to put a catch-all container in 2+ different places.

Specific Changes

  • Added new CustomElementsProvider to host internal-use hash-secured Web Components
  • Added new code block copy button <webchat-xxxxx--code-block-copy-button> where xxxxx is a random hash
  • Chaining package.json via touch so changes to core will trigger rebuild of api, and so on
  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@compulim compulim changed the title [WIP] Add code block copy button Add code block copy button Oct 25, 2024
@compulim compulim marked this pull request as ready for review October 25, 2024 21:59
OEvgeny
OEvgeny previously approved these changes Oct 25, 2024
OEvgeny
OEvgeny previously approved these changes Oct 25, 2024
OEvgeny
OEvgeny previously approved these changes Oct 25, 2024
OEvgeny
OEvgeny previously approved these changes Oct 26, 2024
OEvgeny
OEvgeny previously approved these changes Oct 26, 2024
@compulim compulim merged commit f1d7b19 into microsoft:main Oct 26, 2024
25 checks passed
@compulim compulim deleted the feat-code-block-copy-button branch October 26, 2024 19:00
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