From 55c56abad5bf5077d22cf7f08ab3ad2a462fab07 Mon Sep 17 00:00:00 2001 From: zorkow Date: Thu, 14 Nov 2024 13:47:54 +0100 Subject: [PATCH 1/4] refactor semantic utilities --- ts/semantic_tree/semantic_util.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ts/semantic_tree/semantic_util.ts b/ts/semantic_tree/semantic_util.ts index fc4f568f0..2f1ed14c4 100644 --- a/ts/semantic_tree/semantic_util.ts +++ b/ts/semantic_tree/semantic_util.ts @@ -133,7 +133,7 @@ export function hasMathTag(node: Element): boolean { * @returns True if element is an leaf node. */ function hasLeafTag(node: Element): boolean { - return !!node && LEAFTAGS.indexOf(DomUtil.tagName(node)) !== -1; + return !!node && LEAFTAGS.includes(DomUtil.tagName(node)); } /** @@ -143,7 +143,7 @@ function hasLeafTag(node: Element): boolean { * @returns True if element is an ignore node. */ export function hasIgnoreTag(node: Element): boolean { - return !!node && IGNORETAGS.indexOf(DomUtil.tagName(node)) !== -1; + return !!node && IGNORETAGS.includes(DomUtil.tagName(node)); } /** @@ -153,7 +153,7 @@ export function hasIgnoreTag(node: Element): boolean { * @returns True if element is an empty node. */ export function hasEmptyTag(node: Element): boolean { - return !!node && EMPTYTAGS.indexOf(DomUtil.tagName(node)) !== -1; + return !!node && EMPTYTAGS.includes(DomUtil.tagName(node)); } /** @@ -163,7 +163,7 @@ export function hasEmptyTag(node: Element): boolean { * @returns True if element is an display node. */ export function hasDisplayTag(node: Element): boolean { - return !!node && DISPLAYTAGS.indexOf(DomUtil.tagName(node)) !== -1; + return !!node && DISPLAYTAGS.includes(DomUtil.tagName(node)); } /** @@ -196,10 +196,10 @@ export function purgeNodes(nodes: Element[]): Element[] { continue; } const tagName = DomUtil.tagName(node); - if (IGNORETAGS.indexOf(tagName) !== -1) { + if (IGNORETAGS.includes(tagName)) { continue; } - if (EMPTYTAGS.indexOf(tagName) !== -1 && node.childNodes.length === 0) { + if (EMPTYTAGS.includes(tagName) && node.childNodes.length === 0) { continue; } nodeArray.push(node); @@ -226,7 +226,7 @@ export function isZeroLength(length: string): boolean { 'negativeverythickmathspace', 'negativeveryverythickmathspace' ]; - if (negativeNamedSpaces.indexOf(length) !== -1) { + if (negativeNamedSpaces.includes(length)) { return true; } const value = length.match(/[0-9.]+/); @@ -254,7 +254,7 @@ export function addAttributes(to: SemanticNode, from: Element) { to.attributes[key] = attrs[i].value; to.nobreaking = true; } - if (directSpeechKeys.indexOf(key) !== -1) { + if (directSpeechKeys.includes(key)) { to.attributes['ext-speech'] = attrs[i].value; to.nobreaking = true; } From f22811a2ddbbc214aa0f0de2a528fd1831d42668 Mon Sep 17 00:00:00 2001 From: zorkow Date: Thu, 14 Nov 2024 14:11:49 +0100 Subject: [PATCH 2/4] widen scopeo ignore predicate for tags to encompase html --- ts/semantic_tree/semantic_util.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ts/semantic_tree/semantic_util.ts b/ts/semantic_tree/semantic_util.ts index 2f1ed14c4..d79e49c68 100644 --- a/ts/semantic_tree/semantic_util.ts +++ b/ts/semantic_tree/semantic_util.ts @@ -64,6 +64,11 @@ export enum MMLTAGS { } +/** + * List of all MathML Tags. + */ +const ALLTAGS: string[] = Object.values(MMLTAGS); + /** * List of MathML Tags that are considered to be leafs. */ @@ -143,7 +148,8 @@ function hasLeafTag(node: Element): boolean { * @returns True if element is an ignore node. */ export function hasIgnoreTag(node: Element): boolean { - return !!node && IGNORETAGS.includes(DomUtil.tagName(node)); + return !!node && (IGNORETAGS.includes(DomUtil.tagName(node)) || + !ALLTAGS.includes(DomUtil.tagName(node))); } /** From c03342f34e061adaf25b8e1e2d474559b4395822 Mon Sep 17 00:00:00 2001 From: zorkow Date: Thu, 14 Nov 2024 14:29:12 +0100 Subject: [PATCH 3/4] update tests --- sre-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sre-tests b/sre-tests index 5cce73574..17088191e 160000 --- a/sre-tests +++ b/sre-tests @@ -1 +1 @@ -Subproject commit 5cce73574d2c0bef209db33c899379685bf80289 +Subproject commit 17088191e6b26bc2fc2a2e3ec19d6d7998d944a0 From c9bc32b1d4fae5fa95d7979e377611e647ac9b49 Mon Sep 17 00:00:00 2001 From: zorkow Date: Thu, 14 Nov 2024 15:01:54 +0100 Subject: [PATCH 4/4] update tests --- sre-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sre-tests b/sre-tests index 17088191e..1ca39625b 160000 --- a/sre-tests +++ b/sre-tests @@ -1 +1 @@ -Subproject commit 17088191e6b26bc2fc2a2e3ec19d6d7998d944a0 +Subproject commit 1ca39625bb3a8e3336a0075fd61fb9190186257e