-
Notifications
You must be signed in to change notification settings - Fork 8
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
XML Serialization #36
Conversation
}); | ||
|
||
it('can serialize a CDATASection', () => { | ||
chai.assert.equal(serializer.serializeToString(document.createCDATASection('test')), '<![CDATA[test]]>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CDataSections are special w.r.t serialization, though they are lightly used in our main dependant (FontoXML), it would be nice to add some tests for createCDATASection(']]')
, createCDATASection('&NOT_AN_ENTITY;')
, createCDATASection('<element><!-- xml syntax in CData --></element>')
, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. It is unfortunately possible (through manipulating data after creation) to create a CDataSection containing ]]>
, which will result in invalid XML when serialized. The closest mention of this I could find is a work-around proposed in https://www.w3.org/Bugs/Public/show_bug.cgi?id=16682. The current behavior matches Chrome, Firefox, Edge and Safari, so I guess we should keep it for now and be careful when we mutate CDataSection data.
}); | ||
|
||
it("throws if given something that isn't a node", () => { | ||
chai.assert.throws(() => (slimdom as any).serializeToWellFormedString({ nodeType: 1 }), TypeError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use a cast here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a convenient way to disable type checking for the function call, otherwise TypeScript wouldn't let me pass the object as a Node.
The babili minifier has been renamed, and future versions will use the babel-minify name. This includes related packages, such as the rollup plugin we use. Fixes #37
This implements the XMLSerializer interface and innerHTML / outerHTML getters from the W3C DOM parsing spec. The corresponding setters will hopefully be added once we get a parser implemented in a future release.
Note that the spec contains a few errors that this implementation has to work around:
xml:
to be serialized correctly (the algorithm in the spec would serializexml:id
asns0:id
).This also adds a slimdom.serializeToWellFormedString export, as there would otherwise be no easy way to run the serialization algorithm with the require well-formed flag set.