Syntax highting with rails 7 and highlightjs

January 10, 2023
I ran into a problem with rails 7's turbo when trying to implement highlight js .
I had pinned the highlight js into the importmap file, Imported it into application js and used eventlistener for turbo: load to load the highlightjs . Everything worked in dev.
But as I deployed, somehow turbo load was not working as expected. I noticed that it was only working when i clicked any navigation link and my highlightjs was loading before even my code elements from inside DOM.
Solution : Simple, Undo anything with pin , import and turbo.
load stylesheet and js directly from highlight cdn into the layout.
Screenshot 2023-01-10 at 00.54.05.png 64.3 KB

and in my view directly loaded the highlight js ,
Screenshot 2023-01-10 at 00.55.31.png 67.3 KB

Works for now, Till i figure out why turbo load was not working in production environment. If you have any suggestions feel free to reach out to me.