I am attempting to use prismjs from a file I am importing into a web-component.
Here is the function which is supposed to return the prismjs highlighted code block
import Prism from 'prismjs';
function article() {
const code = `var data = 1`;
const html = Prism.highlight(code, Prism.languages.javascript, 'javascript')
const pre = document.createElement('pre')
const _code = document.createElement('code')
_code.classList = 'language-js'
_code.innerHTML = html
pre.appendChild(_code)
return pre
}
and here is my web-component
export default class PostComponent extends HTMLElement {
constructor() {
super()
this.shadow = this.attachShadow({mode: 'open'})
this.styleSheet = document.createElement('style')
window.addEventListener('popstate', async (e) => {
const path = e.state;
const module = await GetArticle(path)
this.articleName = module.title()
this.canvasApp = module.canvasApp()
this.article = module.article()
this.shadow.replaceChildren(
this.styleSheet,
this.articleName,
this.canvasApp,
this.article
)
});
}
connectedCallback() {
this.RenderView();
}
RenderView() {
this.styleSheet.textContent = Style;
}
}
I am including the prism.min.css from index.html.
What gets ultimately rendered is an unhighlighted code element which is not what I am looking for. I have tried using Prism.highlightAll() in the article() function and the constructor but neither works.