Skip to content

Commit

Permalink
Fix HTML in SVG in HTML
Browse files Browse the repository at this point in the history
Closes GH-18.
  • Loading branch information
wooorm committed Dec 9, 2022
1 parent 9ae39c7 commit 9bbc7f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/index.js
Expand Up @@ -270,13 +270,13 @@ export const raw =
*/
function element(node) {
resetTokenizer()
parser._processToken(startTag(node), webNamespaces.html)
parser._processInputToken(startTag(node))

all(node.children)

if (!htmlVoidElements.includes(node.tagName)) {
resetTokenizer()
parser._processToken(endTag(node))
parser._processInputToken(endTag(node))
}
}

Expand All @@ -286,7 +286,7 @@ export const raw =
*/
function text(node) {
resetTokenizer()
parser._processToken({
parser._processInputToken({
type: characterToken,
chars: node.value,
location: createParse5Location(node)
Expand All @@ -299,7 +299,7 @@ export const raw =
*/
function doctype(node) {
resetTokenizer()
parser._processToken({
parser._processInputToken({
type: doctypeToken,
name: 'html',
forceQuirks: false,
Expand All @@ -315,7 +315,7 @@ export const raw =
*/
function comment(node) {
resetTokenizer()
parser._processToken({
parser._processInputToken({
type: commentToken,
data: node.value,
location: createParse5Location(node)
Expand Down Expand Up @@ -427,7 +427,7 @@ export const raw =
token.location.endLine = posTracker.line
token.location.endCol = posTracker.col + 1
token.location.endOffset = posTracker.offset + 1
parser._processToken(token)
parser._processInputToken(token)
}

// Reset tokenizer:
Expand Down
10 changes: 9 additions & 1 deletion test.js
Expand Up @@ -5,7 +5,7 @@

import test from 'tape'
import {u} from 'unist-builder'
import {h} from 'hastscript'
import {h, s} from 'hastscript'
import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
Expand Down Expand Up @@ -188,6 +188,14 @@ test('raw', (t) => {
'should support template nodes'
)

t.deepEqual(
raw(u('root', [h('p', [h('svg', [s('foreignObject', [h('div')])])])])),
u('root', {data: {quirksMode: false}}, [
h('p', [h('svg', [s('foreignObject', [h('div')])])])
]),
'should support HTML in SVG in HTML'
)

t.deepEqual(
raw(u('root', [u('raw', '<i'), h('b')])),
u('root', {data: {quirksMode: false}}, [h('b')]),
Expand Down

0 comments on commit 9bbc7f3

Please sign in to comment.