Przeglądaj źródła

Count abstract environment in preamble (#28458)

GitOrigin-RevId: 7a69b2cef6e7570e6324ecbd7b6cd3ff61f3cf67
Alf Eaton 11 miesięcy temu
rodzic
commit
b87812d102

+ 28 - 21
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,