addons/isl/src/clipboard.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import platform from './platform';
b69ab319
b69ab3110/** Copy text to the clipboard */
b69ab3111export function clipboardCopyText(text: string) {
b69ab3112 return platform.clipboardCopy(text);
b69ab3113}
b69ab3114
b69ab3115/**
b69ab3116 * Copy text that refers to a URL to the clipboard.
b69ab3117 * If pasted into a rich text input, it will paste as text with a URL link.
b69ab3118 * If pasted into a plain text input, it will just use the text without the url.
b69ab3119 */
b69ab3120export function clipboardCopyLink(text: string, url: string) {
b69ab3121 return platform.clipboardCopy(text, clipboardLinkHtml(text, url));
b69ab3122}
b69ab3123
b69ab3124/**
b69ab3125 * HTML <a> tag for `text` pointing to `url`. Useful for copying rich text links.
b69ab3126 */
b69ab3127export function clipboardLinkHtml(text: string, url: string): string {
b69ab3128 return `<a href="${url}">${text}</a>`;
b69ab3129}