Skip to content

Loading fails if body does not contain div #329

@voegtlel

Description

@voegtlel

Hello,

it may seem strange, but this fails:

<html><head><script>
document.addEventListener("DOMContentLoaded", function() {
  // Uncommenting this makes the loading succeed. It must be a div, e.g. a table does not help.
  //document.body.appendChild(document.createElement('div'));
  let script = document.createElement('script');
  script.src = "https://cdn.jsdelivr.net/npm/mathpix-markdown-it@1.3.8/es5/bundle.js";
  script.onload = function() { window.loadMathJax(); };
  document.head.append(script);
});
</script></head><body></body></html>

with the error:

Error load MathJax => Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

it fails in this place in the bundle.js:

                            if (!document.getElementById("SVG-styles")) {
                                var s = u.MathJax.Stylesheet();
                                document.head.appendChild(s)
                            }

apparently, in the error case, s is not an html node, after adding a div node to the body (the commented line), it becomes a proper html node.

I'm not blocked by this (workaround is commented out), but found it a strange situation and hard to find the error, so I believe this should be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions