Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the local demo the code is not highlighted #20

Open
zanonnicola opened this issue Oct 13, 2017 · 5 comments
Open

In the local demo the code is not highlighted #20

zanonnicola opened this issue Oct 13, 2017 · 5 comments

Comments

@zanonnicola
Copy link

zanonnicola commented Oct 13, 2017

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

@calummoore
Copy link

I can't get this to work either.

@calummoore
Copy link

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:

  1. Update the readme.md to explain how the syntax detection works
  2. Add the decorator to any code blocks, even if no tokens are originally detected.

@mxstbr
Copy link
Collaborator

mxstbr commented Nov 7, 2017

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.

@sebalvarez07
Copy link

Does anyone know how to change the language syntax aside from the defaultSyntax property?

@LuzLabLLC
Copy link

bump, I need some help on adding multiple languages or auto detecting them as you type. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants