
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
draft-js-prism-plugin
Advanced tools
draft-js-prism-plugin
A DraftJS plugin to add syntax highlighting support to your code blocks. Use in combination with draft-js-plugins
.
First, create the plugin and add it to the plugins
array of your PluginsEditor:
import Prism from 'prismjs';
import createPrismPlugin from 'draft-js-prism-plugin';
class MyEditor extends React.Component {
constructor(props) {
super(props);
const prismPlugin = createPrismPlugin({
// It's required to provide your own instance of Prism
prism: Prism
});
this.state = {
plugins: [prismPlugin]
}
}
render() {
return (
<PluginsEditor
plugins={this.state.plugins}
/>
)
}
}
Now add a language
key to the data of the code block you want to highlight:
// TODO: Somehow get a code block and its key, this is up to you
const { block, key } = getCurrentBlock();
if (block.getType() !== "code-block") return;
// Replace the code block with a new one with the data.language changed to "javascript"
const data = block.getData().merge({ language: 'javascript' });
const newBlock = block.merge({ data });
const newContentState = currentContent.merge({
blockMap: blockMap.set(key, newBlock),
selectionAfter: currentSelection
})
// Now that code block will be highlighted as JavaScript!
this.setState({
editorState: EditorState.push(editorState, newContentState, "change-block-data")
})
This code uses the draft-js-prism
decorator by @SamyPesse and is based on code extracted from the draft-js-markdown-shortcuts-plugin
by @ngs.
Licensed under the MIT License, Copyright ©️ 2017 Space Program Inc. See LICENSE.md for more information.
FAQs
Add syntax highlighting support to your DraftJS editor
The npm package draft-js-prism-plugin receives a total of 624 weekly downloads. As such, draft-js-prism-plugin popularity was classified as not popular.
We found that draft-js-prism-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.