From b87812d102ea6ade6ef554b7498d1fcd2a3b7e5b Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 12 Sep 2025 10:21:11 +0100 Subject: [PATCH] Count abstract environment in preamble (#28458) GitOrigin-RevId: 7a69b2cef6e7570e6324ecbd7b6cd3ff61f3cf67 --- .../utils/count-words-in-file.ts | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/services/web/frontend/js/features/word-count-modal/utils/count-words-in-file.ts b/services/web/frontend/js/features/word-count-modal/utils/count-words-in-file.ts index 0d612feb17..3cd2801ae2 100644 --- a/services/web/frontend/js/features/word-count-modal/utils/count-words-in-file.ts +++ b/services/web/frontend/js/features/word-count-modal/utils/count-words-in-file.ts @@ -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,