Open zanonnicola opened 7 years ago
I can't get this to work either.
Ok, so looking at this a bit more. It looks like if there is no code present in the original state, then it will not set the decorator.
You can get around this by making sure it is set during the onChange handler:
onChange = (editorState) => {
const content = editorState.getCurrentContent()
this.setState({
editorState: EditorState.set(editorState, { decorator }),
})
}
You also need to set the syntax, I'm not exactly sure how it determines the syntax it will use, but you can set the default:
const decorator = new PrismDecorator({
// Provide your own instance of PrismJS
prism: Prism,
defaultSyntax: 'javascript',
})
I think two changes would be helpful:
Yeah, this is a super annoying design choice by DraftJS—imo decorators should be bound per-editor not per-state. You'll have to make sure to always set the decorator on any new editor state, PRs to fix the demo would be appreciated.
Does anyone know how to change the language syntax aside from the defaultSyntax property?
bump, I need some help on adding multiple languages or auto detecting them as you type. Thanks!
Hi,
first of all thanks for this project!
I've tried to run the demo locally but the code is not highlighted. Just plain black text. There are no errors in the console either.
Am I missing something?
Thanks, Nicola