Skip to content

Commit 3fa5f4b

Browse files
committed
Fix SVG support
Related to edd3d95.
1 parent 2b1a0d6 commit 3fa5f4b

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
var html = require('property-information/html')
44
var svg = require('property-information/svg')
55
var find = require('property-information/find')
6+
var ns = require('web-namespaces')
7+
var s = require('hastscript/svg')
68
var h = require('hastscript')
79
var xtend = require('xtend')
810
var count = require('ccount')
@@ -48,8 +50,8 @@ function transform(ast, config) {
4850
var node
4951
var pos
5052

51-
if (fn === element && schema.space === 'html' && ast.nodeName === 'svg') {
52-
config.schema = svg
53+
if (fn === element) {
54+
config.schema = ast.namespaceURI === ns.svg ? svg : html
5355
}
5456

5557
if (ast.childNodes) {
@@ -131,6 +133,7 @@ function comment(ast) {
131133

132134
/* Transform an element. */
133135
function element(ast, children, config) {
136+
var fn = config.schema.space === 'svg' ? s : h
134137
var name = ast.tagName
135138
var attributes = ast.attrs
136139
var length = attributes.length
@@ -149,7 +152,7 @@ function element(ast, children, config) {
149152
props[prop] = attribute.value
150153
}
151154

152-
node = h(name, props, children)
155+
node = fn(name, props, children)
153156

154157
if (name === 'template' && 'content' in ast) {
155158
pos = ast.sourceCodeLocation

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"ccount": "^1.0.3",
2323
"hastscript": "^4.0.0",
2424
"property-information": "^4.0.0",
25+
"web-namespaces": "^1.1.2",
2526
"xtend": "^4.0.1"
2627
},
2728
"devDependencies": {

test/fixtures/svg/index.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"type": "element",
4343
"tagName": "svg",
4444
"properties": {
45-
"width": 230,
46-
"height": 120,
45+
"width": "230",
46+
"height": "120",
4747
"viewBox": "0 0 200 200",
4848
"xmlns": "http://www.w3.org/2000/svg",
4949
"xmlnsXLink": "http://www.w3.org/1999/xlink"

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ test('hast-util-from-parse5', function(t) {
320320
type: 'element',
321321
tagName: 'svg',
322322
properties: {
323-
width: 230,
324-
height: 120,
323+
width: '230',
324+
height: '120',
325325
viewBox: '0 0 200 200',
326326
xmlns: 'http://www.w3.org/2000/svg',
327327
xmlnsXLink: 'http://www.w3.org/1999/xlink'

0 commit comments

Comments
 (0)