Count abstract environment in preamble (#28458)

GitOrigin-RevId: 7a69b2cef6e7570e6324ecbd7b6cd3ff61f3cf67
This commit is contained in:
Alf Eaton
2025-09-12 10:21:11 +01:00
committed by Copybot
parent e93593be09
commit b87812d102

View File

@@ -159,6 +159,9 @@ export const countWordsInFile = (
iterateNode(nodeRef, 'header')
return false
},
$Environment(nodeRef) {
return handleEnvironment(nodeRef)
},
})
const bodyMatcher = NodeType.match<
@@ -220,27 +223,7 @@ export const countWordsInFile = (
return false
},
$Environment(nodeRef) {
const envNameNode = nodeRef.node
.getChild('BeginEnv')
?.getChild('EnvNameGroup')
?.getChild('EnvName')
if (envNameNode) {
const envName = content
?.substring(envNameNode.from, envNameNode.to)
.replace(/\*$/, '')
if (envName === 'abstract') {
data.headers++
const contentNode = nodeRef.node.getChild('Content')
if (contentNode) {
iterateNode(contentNode, 'abstract')
}
return false
}
}
return handleEnvironment(nodeRef)
},
BeginEnv() {
return false // ignore text in \begin arguments
@@ -315,6 +298,30 @@ export const countWordsInFile = (
}
}
const handleEnvironment = (nodeRef: SyntaxNodeRef) => {
const envNameNode = nodeRef.node
.getChild('BeginEnv')
?.getChild('EnvNameGroup')
?.getChild('EnvName')
if (envNameNode) {
const envName = content
?.substring(envNameNode.from, envNameNode.to)
.replace(/\*$/, '')
if (envName === 'abstract') {
data.headers++
const contentNode = nodeRef.node.getChild('Content')
if (contentNode) {
iterateNode(contentNode, 'abstract')
}
return false
}
}
}
tree.iterate({
from: 0,
to: preambleExtent.to,