@@ -154,102 +154,108 @@ const parseHTML = (html) => {
154
154
return cheerio . load ( html ) ( "body" ) ;
155
155
} ;
156
156
157
- const getPipedData = ( store ) => ( element , ctx , conditionalTradAs ) => {
158
- const { piped, ...elementData } = element . data ( ) ;
159
- const pipeConfig = PIPE_TYPES [ piped ] ;
157
+ const getPipedData =
158
+ ( store ) => ( element , ctx , isRepeatingSection , conditionalTradAs ) => {
159
+ const { piped, ...elementData } = element . data ( ) ;
160
+ const pipeConfig = PIPE_TYPES [ piped ] ;
160
161
161
- if ( piped === "variable" && element . data ( ) . id === "total" ) {
162
- return `%(total)s` ;
163
- }
162
+ if ( piped === "variable" && element . data ( ) . id === "total" ) {
163
+ return `%(total)s` ;
164
+ }
164
165
165
- if ( ! pipeConfig ) {
166
- return "" ;
167
- }
166
+ if ( ! pipeConfig ) {
167
+ return "" ;
168
+ }
168
169
169
- const entity = pipeConfig . retrieve ( elementData , ctx ) ;
170
+ const entity = pipeConfig . retrieve ( elementData , ctx ) ;
170
171
171
- if ( ! entity ) {
172
- return "" ;
173
- }
172
+ if ( ! entity ) {
173
+ return "" ;
174
+ }
174
175
175
- // Extract 'label' and 'secondaryLabel' values from 'entity'
176
- const { label, secondaryLabel } = entity ;
177
- // Create a new element consisting of both 'label' and 'secondaryLabel' along with 'elementData' for 'DateRange' answer types
178
- const dateRangeElement = { ...elementData , label, secondaryLabel } ;
176
+ // Extract 'label' and 'secondaryLabel' values from 'entity'
177
+ const { label, secondaryLabel } = entity ;
178
+ // Create a new element consisting of both 'label' and 'secondaryLabel' along with 'elementData' for 'DateRange' answer types
179
+ const dateRangeElement = { ...elementData , label, secondaryLabel } ;
179
180
180
- const placeholderName =
181
- elementData . type === "DateRange"
182
- ? pipeConfig . placeholder ( dateRangeElement )
183
- : pipeConfig . placeholder ( entity ) ;
181
+ const placeholderName =
182
+ elementData . type === "DateRange"
183
+ ? pipeConfig . placeholder ( dateRangeElement )
184
+ : pipeConfig . placeholder ( entity ) ;
184
185
185
- const identifier =
186
- elementData . type === "DateRange"
187
- ? pipeConfig . render ( elementData )
188
- : pipeConfig . render ( entity ) ;
186
+ const identifier =
187
+ elementData . type === "DateRange"
188
+ ? pipeConfig . render ( elementData )
189
+ : pipeConfig . render ( entity ) ;
189
190
190
- const answerType = pipeConfig . getType ( entity ) ;
191
+ const answerType = pipeConfig . getType ( entity ) ;
191
192
192
- const fallback = pipeConfig . getFallback ( { ...entity , ...elementData } ) ;
193
+ const fallback = pipeConfig . getFallback ( { ...entity , ...elementData } ) ;
193
194
194
- let placeholder ;
195
+ let placeholder ;
195
196
196
- let dateFormat , unitType ;
197
+ let dateFormat , unitType ;
197
198
198
- if ( entity . properties ) {
199
- dateFormat = entity . properties . format ;
200
- unitType = entity . properties . unit ;
201
- }
199
+ if ( entity . properties ) {
200
+ dateFormat = entity . properties . format ;
201
+ unitType = entity . properties . unit ;
202
+ }
202
203
203
- placeholder = placeholderObjectBuilder (
204
- piped ,
205
- placeholderName ,
206
- identifier ,
207
- dateFormat ,
208
- unitType ,
209
- fallback ,
210
- answerType ,
211
- ctx ,
212
- conditionalTradAs
213
- ) ;
204
+ placeholder = placeholderObjectBuilder (
205
+ piped ,
206
+ placeholderName ,
207
+ identifier ,
208
+ dateFormat ,
209
+ unitType ,
210
+ fallback ,
211
+ answerType ,
212
+ ctx ,
213
+ conditionalTradAs ,
214
+ isRepeatingSection
215
+ ) ;
214
216
215
- store . placeholders = [ ...store . placeholders , placeholder ] ;
217
+ store . placeholders = [ ...store . placeholders , placeholder ] ;
216
218
217
- return `{${ removeDash ( placeholderName ) } }` ;
218
- } ;
219
+ return `{${ removeDash ( placeholderName ) } }` ;
220
+ } ;
219
221
220
- const convertPipes = ( ctx , isMultipleChoiceValue ) => ( html ) => {
221
- if ( ! html ) {
222
- return html ;
223
- }
222
+ const convertPipes =
223
+ ( ctx , isMultipleChoiceValue , isRepeatingSection = false ) =>
224
+ ( html ) => {
225
+ if ( ! html ) {
226
+ return html ;
227
+ }
224
228
225
- const store = {
226
- text : "" ,
227
- placeholders : [ ] ,
228
- } ;
229
+ const store = {
230
+ text : "" ,
231
+ placeholders : [ ] ,
232
+ } ;
229
233
230
- const $ = parseHTML ( html ) ;
231
- const conditionalTradAs =
232
- $ . text ( ) . includes ( "(trad_as)" ) || $ . text ( ) . includes ( "([Trad As])" ) ;
234
+ const $ = parseHTML ( html ) ;
235
+ const conditionalTradAs =
236
+ $ . text ( ) . includes ( "(trad_as)" ) || $ . text ( ) . includes ( "([Trad As])" ) ;
233
237
234
- $ . find ( "[data-piped]" ) . each ( ( index , element ) => {
235
- const $elem = cheerio ( element ) ;
236
- $elem . replaceWith ( getPipedData ( store ) ( $elem , ctx , conditionalTradAs ) ) ;
237
- } ) ;
238
+ $ . find ( "[data-piped]" ) . each ( ( index , element ) => {
239
+ const $elem = cheerio ( element ) ;
240
+ $elem . replaceWith (
241
+ getPipedData ( store ) ( $elem , ctx , isRepeatingSection , conditionalTradAs )
242
+ ) ;
243
+ } ) ;
238
244
239
- store . text = unescapePiping ( $ . html ( ) , isMultipleChoiceValue ) ;
245
+ store . text = unescapePiping ( $ . html ( ) , isMultipleChoiceValue ) ;
240
246
241
- if ( conditionalTradAs ) {
242
- store . text = store . text . replace ( "({trad_as})" , "{trad_as}" ) ;
243
- }
244
-
245
- store . text = store . text . replace ( / \s + $ / , '' ) ;
247
+ if ( conditionalTradAs ) {
248
+ store . text = store . text . replace ( "({trad_as})" , "{trad_as}" ) ;
249
+ }
246
250
247
- if ( ! store . placeholders . length ) {
248
- return store . text ;
249
- }
251
+ store . text = store . text . replace ( / \s + $ / , "" ) ;
250
252
251
- return store ;
252
- } ;
253
+ if ( ! store . placeholders . length ) {
254
+ return store . text ;
255
+ }
256
+
257
+ return store ;
258
+ } ;
253
259
254
260
module . exports = convertPipes ;
255
261
module . exports . getAllAnswers = getAllAnswers ;
0 commit comments