PrismJS / live

Prism Live: Lightweight, extensible editable code editors. A work in progress, try it out at your own risk (and report bugs!) :)
https://live.prismjs.com
MIT License
105 stars 28 forks source link

Unexpected effects of the added \u200b #11

Closed acanalis closed 3 years ago

acanalis commented 3 years ago

Hello!

I was working on a Go playground + Prism app. In essence, I take the code from a prism-live textarea and send it to an API of https://play.golang.org/ to be processed, and I get this error:

./prog.go:8:1: invalid character U+200B in identifier
./prog.go:8:1: syntax error: non-declaration statement outside function body

The problem character is a Zero Width Space character (U+200B) that was added by prism-live.js at line 339, col 13. I don't know how frequently this could happen to others, but maybe it's best to keep a strict copy of the code in the text area.

Thanks for all your work!

LeaVerou commented 3 years ago

Are you getting the code from the textarea or the pre in your code?

acanalis commented 3 years ago

I was getting it from the code element via document.querySelector("#pg-1 code").textContent, where the pg-1 is an id from a container div.

I just checked though: when I take it from the pre element I get the same error.

When I take it from the textarea, I don't get the +U200B, but the content of the textarea is always fixed to the initial one.

LeaVerou commented 3 years ago

Use textarea.value to get the code. The pre/code elements are presentation. I suspect you are getting the initial value because you're using textarea.textContent.

acanalis commented 3 years ago

Thanks, works perfectly! I'm marking this as closed.