SamyPesse / draft-js-prism

Code highlighting for DraftJS using Prism
http://samypesse.github.io/draft-js-prism/
Apache License 2.0
274 stars 36 forks source link

Problems with Java syntax #10

Closed jjkavalam closed 6 years ago

jjkavalam commented 8 years ago

My intention is to use draft-js-prism for Java syntax highlighting.

This is what I got with draft-js-prism in Java syntax:

syntax-higlighting-examples-java

As I have marked, certain characters appear in unexpected colors.

Here are the two steps to reproduce this output:

1. Using the browser save the page at http://samypesse.github.io/draft-js-code/ to local disk

2. Edit dist.js as follows:

dist_js_2 prism_java_2

Here is the snippet that I added:

Prism.languages.java=Prism.languages.extend("clike",{keyword:/\b(abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,number:/\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+(?:e[+-]?\d+)?[df]?\b/i,operator:{pattern:/(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,lookbehind:!0}}),Prism.languages.insertBefore("java","function",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0}});

It was copied over from http://prismjs.com/download.html by checking "Java" as a supported language.

mengfoobar commented 7 years ago

any updates on this issue? I am having the same problems. Not just with java, but other languages as well

echenley commented 7 years ago

@mengfoobar The linked PR above fixes this issue. I had to fork this library and draft-js-code and updated them to fit my use case. Both are pretty clean and comprehensible.

For the record, I doubt this project is actively maintained anymore since the author no longer uses draft-js: https://github.com/facebook/draft-js/pull/388#issuecomment-242704205

mengfoobar commented 7 years ago

@echenley ahh i see. I ended up doing something similar to what @jjkavalam did. which fixes the issue for most languages, but still have some problems with markup (the prismjs tokenize functions creates some pretty messy stuff for markup). Once that was fixed, got into even more issues with multi-lang syntax such as JSX, HTML PHP...etc.

Once i have a more complete implementation, will submit a pull request. Thanks a lot for the help! Bummer that the author moved on

mxstbr commented 7 years ago

I've pinged the author and he's given me commit permissions and publish access on npm to take over maintaining this library. Did you ever get anywhere with that imlementation @mengfoobar?

mengfoobar commented 7 years ago

@mxstbr awesome! I'll clean some stuff up and try to get a PR out this weekend

mxstbr commented 7 years ago

Awesome, can't wait @mengfoobar! Let me know if you need any help :blush:

mxstbr commented 7 years ago

Also, do note that #11, #14 and #18 have attempted to solve this problem, so it'd be great to hear what you think of those solutions and how yours is different/better?

mxstbr commented 6 years ago

Since I didn't get any response here and really needed this, I merged #17 which fixes this issue beautifully.

@mengfoobar if you still have some improvements on top of that I'd love to still have that followup PR!