Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to render XML namespace #47

Closed
wants to merge 4 commits into from
Closed

Conversation

pocke
Copy link
Contributor

@pocke pocke commented Jan 7, 2020

This pull request will add support to render XML namespace with toDOM function.

Usage

toDOM(node) {
  return [
    'http://www.w3.org/2000/svg svg',
    ['use', { "http://www.w3.org/1999/xlink xlink:href": "#YOUR_SVG_ID" }]
  ]
}

This pull request will expand the first item of returned value of toDOM function.
It will receive space-separated string. The first one is XML namespace, and the second is element name.
We can also use XML namespace for attributes in the same way.

related issue

test/test-dom.js Outdated

ist(derivedDOM.innerHTML, declaredDOM.innerHTML)
console.log(derivedDOM.innerHTML);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a leftover debugging statement.

src/to_dom.js Outdated
if (typeof structure == "string")
return {dom: doc.createTextNode(structure)}
if (structure.nodeType != null)
return {dom: structure}
let dom = doc.createElement(structure[0]), contentDOM = null
let contentDOM = null
let [xmlns, tag] = structure[0].split(' ', 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do something involving structure[0].indexOf(" ") to check for the presence of a space, to avoid allocating another array for every element?

src/to_dom.js Outdated
@@ -4,7 +4,8 @@
// itself, or an array.
//
// An array describes a DOM element. The first value in the array
// should be a string—the name of the DOM element. If the second
// should be a string—the name of the DOM element. It also can be
// space-separated the XML namespace and the name. If the second
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the name of the DOM element, optionally prefixed by a namespace URL and a space." is probably a better phrasing.

@pocke
Copy link
Contributor Author

pocke commented Jan 7, 2020

@marijnh Thank you for your reviewing!
I applied the changes to the code with three commits.

If you'd like, I'll squash them to one.

Thanks.

marijnh added a commit that referenced this pull request Jan 7, 2020
@marijnh
Copy link
Member

marijnh commented Jan 7, 2020

Thank you. Merged as 66df625, released as 1.9.0

@marijnh marijnh closed this Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants