Skip to content

Instantly share code, notes, and snippets.

@craftzdog
Last active August 8, 2017 00:48
Show Gist options
  • Save craftzdog/cd968468a0b3d9fcabdb1c424effd902 to your computer and use it in GitHub Desktop.
Save craftzdog/cd968468a0b3d9fcabdb1c424effd902 to your computer and use it in GitHub Desktop.
Copy button plugin
'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