-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
highlight: improve copy to clipboard #569
Comments
Well, I've never used the The usage of the
|
The trick for line numbers is, to filter out the line number nodes before you run regexes on the pure text content. The fixes for all issues are now pushed to |
I knew there had to be a way! That is a much nicer solution. Thanks! |
I have pulled the theme using This puts the following in the clipboard: 1module load CellRanger-ARC/2.0.1
2module load CellRanger/7.1.0
3conda activate /nemo/stp/babs/working/barrinc/conda/envs/scamp My interpretation of the code you committed is that it filters the nodes for elements that contain a "ln" class. But in my rendered site the class of the line numbers is "highlight", I think. I modified the line to the following and the clipboard no long included the leading numbers. I wonder if there is a setup difference that I have that means these classes are different? I tried updating to Hugo 0.113 just in case but that didn't change the class. code.querySelectorAll( '.highlight' ) Hopefully you have a better insight than me but if there is anything I can do to help diagnose further please let me know. |
Thanks for reporting. I've found the culprit. In the configuration of the exampleSite I am using
If I comment this out, it results in a completly different DOM and my fix doesn't work. I can hopefully fix this although it is a really messy DOM soup. |
@ChristopherBarrington Please update and give it another try. LGFM |
Looks good to me too (d62e47f). I tried in a variety of pages contexts (in tabs, on the page alone etc) and all worked as-expected. thank you very much! |
- currently the only option until #169 is implemented - also mandatory for printing
Using the
highlight
shortcode withlinenos=true
gives line numbers. When the copy to clipboard button is used on a code block, the line numbers are prepended to the code, exactly as-is from the code block.Will put the following into my clipboard:
I'm not good with JavaScript but wanted to have a try at making a solution. In my website it seems to work, but I don't know if this solution may break other things in your code or if there is a better way to solve the problem (I'd be keen to know).
hugo-theme-relearn/static/js/theme.js
Line 482 in a135b2a
There are lots of possibilities as to what highlight blocks could contain. I think the below is quite generic but it is based on an assumption that line numbers are the first non-space on every line (which fails if every line of code has numbers at the start?!).
I noticed that the elements for line numbers and code content are different but could not find a way to extract only the code-containing
span
elements so came up with this (mess).The text was updated successfully, but these errors were encountered: