Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #307 from Sebobo/t/306
Browse files Browse the repository at this point in the history
Feature: Introduced support for creating elements in other XML namespaces. See ckeditor/ckeditor5#1842.

Thanks @Sebobo!
  • Loading branch information
Reinmar authored Oct 8, 2019
2 parents 0cf5187 + c146c53 commit 37fbcb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dom/createelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import { isString } from 'lodash-es';
* @returns {Element} Created element.
*/
export default function createElement( doc, name, attributes = {}, children = [] ) {
const element = doc.createElement( name );
const namespace = attributes instanceof Object ? attributes.xmlns : null;
const element = namespace ? doc.createElementNS( namespace, name ) : doc.createElement( name );

for ( const key in attributes ) {
element.setAttribute( key, attributes[ key ] );
Expand Down
9 changes: 9 additions & 0 deletions tests/dom/createelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ describe( 'createElement', () => {
expect( p.getAttribute( 'class' ) ).to.equal( 'foo' );
} );

it( 'should create element with namespace', () => {
const namespace = 'http://www.w3.org/2000/svg';
const svg = createElement( document, 'svg', { xmlns: namespace } );

expect( svg.tagName.toLowerCase() ).to.equal( 'svg' );
expect( svg.getAttribute( 'xmlns' ) ).to.equal( namespace );
expect( svg.createSVGRect ).to.be.a( 'function' );
} );

it( 'should create element with child text node', () => {
const p = createElement( document, 'p', null, 'foo' );

Expand Down

0 comments on commit 37fbcb9

Please sign in to comment.