You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I usually publish web pages as HTML that uses XML syntax, with an XML declaration, then a DOCTYPE declaration, and then a namespace declaration on the root element. A sample document begins:
I use a filename extension .xhtml and my server returns the request with media type application/xhtml+xml. Today's version of the "living standard" does not describe any of this as invalid or non-conformant (https://html.spec.whatwg.org/multipage/xhtml.html#the-xhtml-syntax, although they do recommend against it), and except for the issue described below it seems to work.
The issue is that the strategy described above works with almost all of the prismjs features that I use, but not with line highlighting. A lazy solution would be to change my publication strategy, which isn't out of the question, but I would prefer—if possible—to find a way to persuade the prismjs line-numbering plugin to work with my current architecture. I am not opening a conversation about whether using the XML-syntax version of HTML is a Good Idea, which would be entirely out of scope here; my question is only about whether prismjs line numbering could be modified in order to be compatible with XML syntax. In my experience these types of incompatibilities involve optional features of the non-XML syntax (unquoted attribute values, attribute names without values, tag omission, etc.), and because those features are optional, the stricter, XML-syntax versions often represent a solution that works for everyone. On the other hand, if line numbering in prismjs is breaking apart input elements and rewriting them in ways that cannot realistically be expressed with the stricter XML syntax, that would suggest a higher (and perhaps unrealistic) cost of supporting line numbering with XML syntax.
The console error message when I try to highlight lines is:
prism.js:29 Uncaught SyntaxError: Failed to set the 'innerHTML' property on 'Element': The provided markup is invalid XML, and therefore cannot be inserted into an XML document.
at Object.highlightLines (prism.js:29:649)
at e (prism.js:29:2737)
at Object.run (prism.js:3:4474)
at u (prism.js:3:3236)
at Object.highlightElement (prism.js:3:3721)
at Object.highlightAllUnder (prism.js:3:2810)
at Object.highlightAll (prism.js:3:2404)
at XMLDocument.f (prism.js:3:7029)
and the location of the error within line 29 appears to be:
I think I understand why this is happening: prismjs is injecting markup in a way the the version of HTML that does not require XML well-formedness is able to parse, but it breaks on my page because I'm asking for the XML-syntax version of HTML.
Would anyone happen to know whether this apparent incompatibility is reconcilable?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
I usually publish web pages as HTML that uses XML syntax, with an XML declaration, then a DOCTYPE declaration, and then a namespace declaration on the root element. A sample document begins:
I use a filename extension .xhtml and my server returns the request with media type
application/xhtml+xml. Today's version of the "living standard" does not describe any of this as invalid or non-conformant (https://html.spec.whatwg.org/multipage/xhtml.html#the-xhtml-syntax, although they do recommend against it), and except for the issue described below it seems to work.The issue is that the strategy described above works with almost all of the prismjs features that I use, but not with line highlighting. A lazy solution would be to change my publication strategy, which isn't out of the question, but I would prefer—if possible—to find a way to persuade the prismjs line-numbering plugin to work with my current architecture. I am not opening a conversation about whether using the XML-syntax version of HTML is a Good Idea, which would be entirely out of scope here; my question is only about whether prismjs line numbering could be modified in order to be compatible with XML syntax. In my experience these types of incompatibilities involve optional features of the non-XML syntax (unquoted attribute values, attribute names without values, tag omission, etc.), and because those features are optional, the stricter, XML-syntax versions often represent a solution that works for everyone. On the other hand, if line numbering in prismjs is breaking apart input elements and rewriting them in ways that cannot realistically be expressed with the stricter XML syntax, that would suggest a higher (and perhaps unrealistic) cost of supporting line numbering with XML syntax.
The console error message when I try to highlight lines is:
and the location of the error within line 29 appears to be:
I think I understand why this is happening: prismjs is injecting markup in a way the the version of HTML that does not require XML well-formedness is able to parse, but it breaks on my page because I'm asking for the XML-syntax version of HTML.
Would anyone happen to know whether this apparent incompatibility is reconcilable?
All reactions