@@ -14,6 +14,18 @@ const CELL_END = Symbol("cell-end");
1414type TextPart = string | typeof CELL_START | typeof CELL_END | { fallback : string } ;
1515
1616const TRUNCATED = "\n\n[Extracted text truncated at document extraction limits.]" ;
17+ // Parts the document never displays: tracked deletions and moves, field codes, phonetic guides.
18+ const HIDDEN = new Set ( [
19+ "script" ,
20+ "style" ,
21+ "binary-data" ,
22+ "rPh" ,
23+ "delText" ,
24+ "moveFrom" ,
25+ "instrText" ,
26+ "delInstrText" ,
27+ "tracked-changes" ,
28+ ] ) ;
1729
1830class Truncation extends Error { }
1931
@@ -67,7 +79,7 @@ function* all(node: XmlNode, name: string | readonly string[]): Generator<XmlNod
6779 }
6880}
6981function * text ( node : XmlNode ) : Generator < string , void > {
70- if ( [ "script" , "style" , "binary-data" , "rPh" ] . includes ( node . name ) ) return ;
82+ if ( HIDDEN . has ( node . name ) ) return ;
7183 if ( [ "tab" , "cell" ] . includes ( node . name ) ) yield "\t" ;
7284 else if ( [ "br" , "line-break" , "cr" ] . includes ( node . name ) ) yield "\n" ;
7385 else if ( node . spaceCount !== undefined ) {
@@ -80,7 +92,7 @@ function* text(node: XmlNode): Generator<string, void> {
8092 }
8193}
8294function * paragraphs ( node : XmlNode ) : Generator < TextPart , void > {
83- if ( [ "script" , "style" , "binary-data" ] . includes ( node . name ) ) return ;
95+ if ( HIDDEN . has ( node . name ) ) return ;
8496 for ( const child of node . children ) {
8597 if ( typeof child === "string" ) yield child ;
8698 else if ( [ "br" , "line-break" , "cr" ] . includes ( child . name ) ) yield "\n" ;
@@ -137,11 +149,7 @@ function odfValue(cell: XmlNode): string {
137149function hasCellText ( cell : XmlNode ) : boolean {
138150 if ( odfValue ( cell ) . trim ( ) ) return true ;
139151 // Space markers can have enormous repeat counts; emptiness never requires expanding them.
140- if (
141- [ "script" , "style" , "binary-data" , "rPh" ] . includes ( cell . name ) ||
142- cell . spaceCount !== undefined
143- )
144- return false ;
152+ if ( HIDDEN . has ( cell . name ) || cell . spaceCount !== undefined ) return false ;
145153 return cell . children . some ( ( child ) =>
146154 typeof child === "string" ? ! ! child . trim ( ) : hasCellText ( child ) ,
147155 ) ;
0 commit comments