Last active
August 8, 2017 00:48
-
-
Save craftzdog/cd968468a0b3d9fcabdb1c424effd902 to your computer and use it in GitHub Desktop.
Copy button plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use babel' | |
import { React } from 'inkdrop' | |
function createCodeBlockClass (OriginalCode) { | |
return class CodeBlock extends React.Component { | |
static propTypes = { | |
className: PropTypes.string, | |
lang: PropTypes.string, | |
children: PropTypes.any | |
} | |
render () { | |
return ( | |
<div> | |
{/* COPY BUTTON GOES HERE */} | |
<OriginalCode {...this.props} /> | |
</div> | |
) | |
} | |
} | |
} | |
module.exports = { | |
activate () { | |
const { MDEPreview } = inkdrop.components.classes | |
if (MDEPreview) { | |
// override `code` component | |
this.originalCode = MDEPreview.remarkReactOptions.remarkReactComponents.code | |
MDEPreview.remarkReactOptions.remarkReactComponents.code = createCodeBlockClass(this.originalCode) | |
} | |
}, | |
deactivate () { | |
const { MDEPreview } = inkdrop.components.classes | |
if (MDEPreview) { | |
MDEPreview.remarkReactOptions.remarkReactComponents.code = this.originalCode | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment