@@ -112,6 +112,50 @@ class ToCiceroMarkVisitor {
112
112
return isBorderPresent ;
113
113
}
114
114
115
+ /**
116
+ * Checks if the node is a codeblock or not
117
+ *
118
+ * @param {Array } paragraphProperties paragraph styling properties
119
+ * @returns {boolean } true if the node is of type codeblock or else, false
120
+ */
121
+ checkCodeBlockProperties ( paragraphProperties ) {
122
+ let isDesiredTopBorderPresent = false ;
123
+ let isDesiredBottomBorderPresent = false ;
124
+ let isDesiredLeftBorderPresent = false ;
125
+ let isDesiredRightBorderPresent = false ;
126
+ let isDesiredShadePresent = false ;
127
+
128
+ for ( const property of paragraphProperties ) {
129
+ if ( property . name === 'w:pBdr' ) {
130
+ // do something
131
+ for ( const borderProperty of property . elements ) {
132
+ if ( borderProperty . attributes [ 'w:color' ] === 'CCCCCC' ) {
133
+ if ( borderProperty . name === 'w:top' ) {
134
+ isDesiredTopBorderPresent = true ;
135
+ } else if ( borderProperty . name === 'w:bottom' ) {
136
+ isDesiredBottomBorderPresent = true ;
137
+ } else if ( borderProperty . name === 'w:left' ) {
138
+ isDesiredLeftBorderPresent = true ;
139
+ } else if ( borderProperty . name === 'w:right' ) {
140
+ isDesiredRightBorderPresent = true ;
141
+ }
142
+ }
143
+ }
144
+ } else if ( property . name === 'w:shd' ) {
145
+ if ( property . attributes [ 'w:fill' ] === 'F8F8F8' ) {
146
+ isDesiredShadePresent = true ;
147
+ }
148
+ }
149
+ }
150
+ return (
151
+ isDesiredTopBorderPresent &&
152
+ isDesiredBottomBorderPresent &&
153
+ isDesiredLeftBorderPresent &&
154
+ isDesiredRightBorderPresent &&
155
+ isDesiredShadePresent
156
+ ) ;
157
+ }
158
+
115
159
/**
116
160
* Constructs a ciceroMark Node for inline element from the information.
117
161
*
@@ -213,10 +257,13 @@ class ToCiceroMarkVisitor {
213
257
/**
214
258
* Traverses for properties and value.
215
259
*
216
- * @param {Array } node Node to be traversed
217
- * @param {object } nodeInformation Information for the current node
260
+ * @param {Array } node Node to be traversed
261
+ * @param {object } nodeInformation Information for the current node
262
+ * @param {Boolean } calledByCodeBlock Is function called by codeblock checker
263
+ * @returns {string } Value in <w:t> tags
218
264
*/
219
- fetchFormattingProperties ( node , nodeInformation ) {
265
+ fetchFormattingProperties ( node , nodeInformation , calledByCodeBlock = false ) {
266
+ let ooxmlTagTextValue = '' ;
220
267
for ( const runTimeNodes of node . elements ) {
221
268
if ( runTimeNodes . name === 'w:rPr' ) {
222
269
let colorCodePresent = false ;
@@ -245,13 +292,21 @@ class ToCiceroMarkVisitor {
245
292
nodeInformation . nodeType = TRANSFORMED_NODES . code ;
246
293
}
247
294
} else if ( runTimeNodes . name === 'w:t' ) {
248
- nodeInformation . value = runTimeNodes . elements ? runTimeNodes . elements [ 0 ] . text : ' ' ;
249
- this . JSONXML = [ ...this . JSONXML , nodeInformation ] ;
295
+ if ( calledByCodeBlock ) {
296
+ ooxmlTagTextValue += runTimeNodes . elements ? runTimeNodes . elements [ 0 ] . text : '' ;
297
+ } else {
298
+ ooxmlTagTextValue = runTimeNodes . elements ? runTimeNodes . elements [ 0 ] . text : ' ' ;
299
+ nodeInformation . value = ooxmlTagTextValue ;
300
+ this . JSONXML = [ ...this . JSONXML , nodeInformation ] ;
301
+ }
302
+ } else if ( runTimeNodes . name === 'w:br' ) {
303
+ ooxmlTagTextValue += '\n' ;
250
304
} else if ( runTimeNodes . name === 'w:sym' ) {
251
305
nodeInformation . nodeType = TRANSFORMED_NODES . softbreak ;
252
306
this . JSONXML = [ ...this . JSONXML , nodeInformation ] ;
253
307
}
254
308
}
309
+ return ooxmlTagTextValue ;
255
310
}
256
311
257
312
/**
@@ -273,6 +328,23 @@ class ToCiceroMarkVisitor {
273
328
274
329
const isThematicBreak = this . checkThematicBreakProperties ( subNode . elements [ 0 ] . elements ) ;
275
330
331
+ const isCodeBlock = this . checkCodeBlockProperties ( subNode . elements [ 0 ] . elements ) ;
332
+
333
+ if ( isCodeBlock ) {
334
+ let text = '' ;
335
+ for ( const codeBlockSubNode of subNode . elements ) {
336
+ if ( codeBlockSubNode . name === 'w:r' ) {
337
+ text = this . fetchFormattingProperties ( codeBlockSubNode , undefined , true ) ;
338
+ }
339
+ }
340
+ const codeBlockNode = {
341
+ $class : TRANSFORMED_NODES . codeBlock ,
342
+ text,
343
+ } ;
344
+ this . nodes = [ ...this . nodes , codeBlockNode ] ;
345
+ continue ;
346
+ }
347
+
276
348
if ( isThematicBreak ) {
277
349
const thematicBreakNode = {
278
350
$class : TRANSFORMED_NODES . thematicBreak ,
0 commit comments