Skip to content

innerHTML breaks syntax highlighting #85

@maikhorma

Description

@maikhorma

I'm on nodejs 18.3, so I'm wondering if it's a compatibility thing, but here's a codesandbox that demonstrates it.

I was able to make it to work by hacking here to do this:

            if (innerHTML) {
                var wrapped="<pre><code>" +  children + "</code></pre>";
                props.dangerouslySetInnerHTML = { __html: wrapped };
                ...

This is because this function doesn't find the element thanks to lack of <pre><code> wrapper:

    highlightCode() {
        const nodes = this.el.querySelectorAll('pre code');

        for (let i = 0; i < nodes.length; i++) {
            hljs.highlightBlock(nodes[i])
        }
    }

I'd do a PR myself but i'm a novice at this js and react stuff and i'm pretty sure my hack isn't the right way to fix it. If you want to explain what I need to do I can submit the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions