Merge pull request #177 from aeschylus/master

fixes #175 - copy to clipboard
This commit is contained in:
Keyan 2022-10-04 12:31:08 -05:00 committed by GitHub
commit 88b0ab3087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -13,6 +13,12 @@ import GithubSlugger from 'github-slugger'
import Link from '../svgs/link.svg' import Link from '../svgs/link.svg'
import {toString} from 'mdast-util-to-string' import {toString} from 'mdast-util-to-string'
function copyToClipboard (id) {
if (navigator && navigator.clipboard && navigator.clipboard.writeText)
return navigator.clipboard.writeText(str);
return Promise.reject('The Clipboard API is not available.');
}
function myRemarkPlugin () { function myRemarkPlugin () {
return (tree) => { return (tree) => {
visit(tree, (node) => { visit(tree, (node) => {
@ -38,7 +44,13 @@ function Heading ({ h, slugger, noFragments, topLevel, children, node, ...props
return ( return (
<div className={styles.heading}> <div className={styles.heading}>
{React.createElement(h, { id, ...props }, children)} {React.createElement(h, { id, ...props }, children)}
{!noFragments && topLevel && <a className={styles.headingLink} href={`#${id}`}><Link width={18} height={18} className='fill-grey' /></a>} {!noFragments && topLevel && <a className={styles.headingLink} href={`#${id}`}><Link
onClick={() => copyToClipboard(id)}
width={18}
height={18}
className='fill-grey'
/>
</a>}
</div> </div>
) )
} }