Using the Prism.js API with a clever bit of Javascript might do the trick! Let's make this a webpage that uses its own code as an example! A recursion joke and a practical guide all rolled into one. It's like code-ception!
First we link to the stylesheet we want to use. In this case, there is the one I use for my pages, and one for Prism's syntax highlighting. Ignore the lines for my headers 😜
We then embed the objects that will be generated by the Javascript code. Note the "id".
And this is the Javascript code that goes within the HTML script tags. The function takes in the id, URL and start/end lines to extract the code from.