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

Adding a code snippet with javascript function does not highlight code but after press spacebar or other key #17

Open
hermanvl opened this issue May 24, 2021 · 1 comment

Comments

@hermanvl
Copy link

Hello, I am using prism live in a textarea and it works fine but when I try to add a code snippet using a button onclick function (document.getElementById("content").innerHTML += header;), the code is added but invisible until i press spacebar or another key, then it shows up nicely highlighted as expected. Is there a way to force it so it is highlighted right away?
It works when I just paste it with ctrl-v but not with button onclick.
thanks

@hermanvl hermanvl changed the title Adding a code snippet with javascript function does not highlight code but after click Adding a code snippet with javascript function does not highlight code but after press spacebar or other key May 27, 2021
@dordchn
Copy link

dordchn commented Apr 4, 2022

You can trigger the highlighting code by dispatching the 'input' event on the textarea.

textarea.value = code;
textarea.dispatchEvent(new InputEvent("input"));

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

2 participants