@@ -12,10 +12,14 @@ import {
12
12
recursivelyProcessTextSnippetJson
13
13
} from "./processingFunctions" ;
14
14
15
+ import { getIdForExerciseJson } from "./processingFunctions/processExerciseJson" ;
16
+
15
17
import {
16
18
generateSearchData
17
19
} from "./generateSearchData" ;
18
20
21
+ import { parseAndInsertToIndexTrie , parseAndInsertToIdToContentMap } from "./searchRewrite" ;
22
+
19
23
let paragraph_count = 0 ;
20
24
let heading_count = 0 ;
21
25
let footnote_count = 0 ;
@@ -120,6 +124,31 @@ const processLatex = (node, obj, inline) => {
120
124
obj [ "body" ] = math ;
121
125
obj [ "tag" ] = "LATEX" ;
122
126
} ;
127
+ let latest_exercise_json_id = undefined ;
128
+ const tagsWithIds = {
129
+ "#document" : ( ) => "" ,
130
+ SUBSUBSECTION : ( ) => subsubsection_count > 0 ? `#sec${ chapterIndex } .${ subsubsection_count } ` :"" ,
131
+ TEXT :( ) => "#p" + paragraph_count ,
132
+ SUBHEADING : ( ) => `#h${ heading_count } ` ,
133
+ SUBSUBHEADING : ( ) => `#h${ heading_count } ` ,
134
+ SECTION : ( ) => `#h${ heading_count } ` ,
135
+ FOOTNOTE : ( ) => `#footnote-link-${ footnote_count } ` ,
136
+ DISPLAYFOOTNOTE : ( ) => `#footnote-${ display_footnote_count } ` ,
137
+ //SNIPPET: () => `${snippet_count}`,
138
+
139
+ EXERCISE : ( ) => latest_exercise_json_id ,
140
+ DISPLAYFOOTNOTE : ( ) => `#footnote-${ display_footnote_count } ` ,
141
+ } ;
142
+ const findParentID = ( node ) => {
143
+ let parent = node . parentNode ;
144
+ while ( parent ) {
145
+ if ( tagsWithIds [ parent . nodeName ] ) {
146
+ return `${ chapterIndex } ` + tagsWithIds [ parent . nodeName ] ( ) ;
147
+ } else {
148
+ parent = parent . parentNode ;
149
+ }
150
+ }
151
+ }
123
152
124
153
const processTextFunctions = {
125
154
// Text tags: tag that is parsed as text
@@ -132,6 +161,10 @@ const processTextFunctions = {
132
161
}
133
162
}
134
163
} ,
164
+ INDEX : ( node , obj ) => {
165
+ const id = findParentID ( node ) ;
166
+ parseAndInsertToIndexTrie ( node , { id} ) ;
167
+ } ,
135
168
136
169
AMP : ( _node , obj ) => {
137
170
processText ( "&" , obj ) ;
@@ -181,6 +214,7 @@ const processTextFunctions = {
181
214
} ,
182
215
183
216
EXERCISE : ( node , obj ) => {
217
+ latest_exercise_json_id = getIdForExerciseJson ( node ) ;
184
218
exercise_count += 1 ;
185
219
processExerciseJson ( node , obj , chapArrIndex , exercise_count ) ;
186
220
} ,
@@ -310,6 +344,8 @@ const processTextFunctions = {
310
344
} ,
311
345
312
346
SNIPPET : ( node , obj ) => {
347
+ const indexNodes = node . getElementsByTagName ( "INDEX" ) ;
348
+
313
349
if ( node . getAttribute ( "HIDE" ) == "yes" ) {
314
350
return ;
315
351
} else if ( node . getAttribute ( "LATEX" ) == "yes" ) {
@@ -349,6 +385,10 @@ const processTextFunctions = {
349
385
obj [ "body" ] = obj [ "body" ] . replace ( matchStr , newStr ) ;
350
386
}
351
387
}
388
+
389
+ for ( let i = 0 ; i < indexNodes . length ; i ++ ) {
390
+ processTextJson ( indexNodes [ i ] , { } ) ;
391
+ }
352
392
353
393
return ;
354
394
}
@@ -358,6 +398,9 @@ const processTextFunctions = {
358
398
obj [ "latex" ] = false ;
359
399
obj [ "id" ] = snippet_count ;
360
400
processSnippetJson ( node , obj ) ;
401
+ for ( let i = 0 ; i < indexNodes . length ; i ++ ) {
402
+ processTextJson ( indexNodes [ i ] , { } ) ;
403
+ }
361
404
} ,
362
405
363
406
SUBINDEX : ( node , obj ) => {
@@ -520,7 +563,8 @@ export const parseXmlJson = (doc, arr, filename) => {
520
563
} else {
521
564
displayTitle = chapterIndex + "\u00A0\u00A0" + chapterTitle ;
522
565
}
523
-
566
+
567
+ latest_exercise_json_id = undefined ;
524
568
paragraph_count = 0 ;
525
569
footnote_count = 0 ;
526
570
display_footnote_count = 0 ;
@@ -571,6 +615,7 @@ export const parseXmlJson = (doc, arr, filename) => {
571
615
recursiveProcessTextJson ( name . nextSibling , arr , title ) ;
572
616
}
573
617
618
+ parseAndInsertToIdToContentMap ( arr , chapterIndex ) ;
574
619
generateSearchData ( doc , filename ) ;
575
620
576
621
} ;
0 commit comments