Closed (fixed)
Project:
Highlight Js syntax highlighter
Version:
1.1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 Nov 2025 at 09:47 UTC
Updated:
1 Dec 2025 at 08:59 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #3
norman.lolComment #4
norman.lolDamn, it's still there..
It's not the wrapping..
It's
ClipboardJSthat creates these duplicates..Comment #5
norman.lolAhhhh now I get it..
Look:
First we run this:
once('highlight_js', 'code', context).forEach(function (element) {And inside there we run this:
$('code').each(function (i, block) {So, there's always going to be exactly that amount of wrappers and highlighting attempts as there are
<code>occurrences on the page.Comment #6
norman.lolComment #7
norman.lolComment #9
a.dmitriiev commentedI have update MR, please check. I have also included the change from this issue #3550427: The highlight js code runs on all code blocks
Comment #10
norman.lolThis looks much nicer 🤩 Much better to remove the duplicate foreach 👍🏻
But..
..now we again run highlightAll multiple times:
which again results in browser console full of this:
Comment #11
norman.lolSo either we move
hljs.highlightAlloutside of the loop.Or we hightlight each block separately via
hljs.highlightBlock(block).Seen on https://stackoverflow.com/a/15177245/2199525:
Comment #12
a.dmitriiev commentedI checked the
highlightBlockand it turned out that it is deprecated andhighlightElementshould be used instead. I have updated MR, please checkComment #13
norman.lolhighlightElementis working fine but now the copy functionality is missing. Looks like as ifelement.wrap('<div class="code-container"></div>');is not executed, checking..Comment #14
norman.lolAh, it is working, but only for
<pre>, not for<code>..Comment #15
norman.lolOkay, I think I now managed to maintain the existing logic:
<code>elements for the copy functionality to work<pre><code>elements (inline<code>elements without<pre>parent must not have it)<pre><code>elements (inline<code>elements without<pre>parent must not have it)Comment #16
a.dmitriiev commented@norman.lol, are you sure there is need to wrap
codeonly tags in container and to have the copy button? Because this ends up in situations like this:The code tag is not inline anymore and the copy button is far away from the code itself.
Comment #17
a.dmitriiev commentedComment #18
norman.lolOur designers provided a nice design for the inline copy button.
I implemented this now (to all code blocks, not just the inline ones).
I needed to add two new config options
success_bg_transparentandsuccess_bg_colorfor it, and added backwards compatible values in an update hook.On the way I also added the missing config install and schema.
Comment #19
norman.lolIt would be really easy now to also add an option
inline_enable(default TRUE) to let people completely disable highlighting and copy functionality on inline elements.. We can then simplyreturnearly in the JS..Comment #20
norman.lol(I've left the success message icon out for now. Thinking it's maybe a bit too opinionated.)
Comment #21
norman.lol(Or just we maybe add a textarea option in the config form allowing people to paste SVG markup? 🤔)
Comment #22
a.dmitriiev commentedMinor issue with the "Copied" message, see the screenshot below:
Comment #23
a.dmitriiev commentedComment #24
norman.lolI added a CSS rule that simply hides the
.copy-btnwhen the.copy-messageis not empty. Since.copy-messagealways only gets populated after the button click and then emptied again after 2 seconds, that looks like a solid fix.Comment #25
a.dmitriiev commentedThe inline
codelooks better now, but I am not sure that for thepre codethis tooltip is the best solution, maybe let's leave it for now how it was before, just in top right corner?Comment #26
norman.lolLatest feedback included: Inside big code blocks the button is inside the code block in the top right corner again.
I also managed to get the font-family inherited from the body tag instead of from the pre element (monospace).
Comment #27
norman.lolGreen lights from @f0ns over from the other issue:
https://www.drupal.org/project/highlight_js/issues/3550427#comment-16346547
Comment #29
a.dmitriiev commentedI made a small adjustment to the update hook and merged! Thank you all!