fixes #175 - copy to clipboard
This commit is contained in:
parent
beef34abfa
commit
41dacc0d80
|
@ -12,6 +12,12 @@ import React, { useEffect, useState } from 'react'
|
||||||
import GithubSlugger from 'github-slugger'
|
import GithubSlugger from 'github-slugger'
|
||||||
import Link from '../svgs/link.svg'
|
import Link from '../svgs/link.svg'
|
||||||
|
|
||||||
|
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) => {
|
||||||
|
@ -39,11 +45,18 @@ function Heading ({ h, slugger, noFragments, topLevel, children, node, ...props
|
||||||
}
|
}
|
||||||
return acc + cur.replace(/[^\w\-\s]+/gi, '')
|
return acc + cur.replace(/[^\w\-\s]+/gi, '')
|
||||||
}, ''))
|
}, ''))
|
||||||
|
console.log(id)
|
||||||
|
|
||||||
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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue