Skip to content

Commit

Permalink
Move xmlns value to a static value on the class.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Jan 29, 2024
1 parent 429b347 commit a4875e8
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions ts/adaptors/lite/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export class LiteParser implements MinDOMParser<LiteDocument> {
script: true
};

public static XMLNS: {[name: string]: string} = {
svg: 'http://www.w3.org/2000/svg',
math: 'http://www.w3.org/1998/Math/MathML',
html: 'http://www.w3.org/1999/xhtml'
};

/**
* @override
*/
Expand Down Expand Up @@ -365,8 +371,18 @@ export class LiteParser implements MinDOMParser<LiteDocument> {
*/
protected allAttributes(adaptor: LiteAdaptor, node: LiteElement, xml: boolean): AttributeData[] {
let attributes = adaptor.allAttributes(node);
//
// If we aren't in XML mode, just use the attributes given
//
if (!xml) {
return attributes;
}
//
// Check that we know the namespace for the kind of node
//
const kind = adaptor.kind(node);
if (!xml || (kind !== 'svg' && kind !== 'math' && kind !== 'html')) {
const xmlns = (this.constructor as typeof LiteParser).XMLNS;
if (!xmlns.hasOwnProperty(kind)) {
return attributes;
}
//
Expand All @@ -380,14 +396,7 @@ export class LiteParser implements MinDOMParser<LiteDocument> {
//
// Add one of it is missing
//
attributes.push({
name: 'xmlns',
value: ({
svg: 'http://www.w3.org/2000/svg',
math: 'http://www.w3.org/1998/Math/MathML',
html: 'http://www.w3.org/1999/xhtml'
})[kind]
});
attributes.push({name: 'xmlns', value: xmlns[kind]});
return attributes;
}

Expand Down

0 comments on commit a4875e8

Please sign in to comment.