@@ -158,6 +158,28 @@ function getHighlightedRowStyle(darkMode: boolean) {
158158 ` ;
159159}
160160
161+ const mergeAsterisks = arr => {
162+ return arr . reduce ( ( acc , curr , i , array ) => {
163+ if (
164+ curr === '*' &&
165+ array [ i + 1 ] === '*' &&
166+ array [ i + 2 ] === '*' &&
167+ typeof array [ i + 3 ] === 'string' &&
168+ array [ i + 4 ] === '*' &&
169+ array [ i + 5 ] === '*' &&
170+ array [ i + 6 ] === '*'
171+ ) {
172+ // Push the transformed string
173+ acc . push ( `***${ array [ i + 3 ] } ***` ) ;
174+ // Skip the next 6 elements
175+ array . splice ( i , 7 ) ;
176+ } else {
177+ acc . push ( curr ) ;
178+ }
179+ return acc ;
180+ } , [ ] ) ;
181+ } ;
182+
161183interface LineTableRowProps {
162184 lineNumber ?: number ;
163185 children : React . ReactNode ;
@@ -247,7 +269,7 @@ export function flattenNestedTree(
247269 return function (
248270 entity : string | TokenObject ,
249271 ) : string | FlatTokenObject | Array < string | FlatTokenObject > {
250- console . log ( { entity } ) ;
272+ // console.log({ entity });
251273 if ( isString ( entity ) ) {
252274 if ( parentKinds . length > 0 ) {
253275 return {
@@ -258,52 +280,54 @@ export function flattenNestedTree(
258280 ) ,
259281 children : [ entity ] ,
260282 } ;
261- } else if ( bracketArray . some ( sub => entity . includes ( sub ) ) ) {
262- // The plugin returns {{ testing }} like this:
263- // entity: "{"
264- // entity: "{ "
265- // entity: "testing }} "
266-
267- if ( entity . includes ( '{' ) ) {
268- // This is a bracket that has no space after it, meaning there is a string directly after it e.g. "{{"
269- const singleBracket = '{' ;
270-
271- // This is a bracket with a space after it and without a new line e.g. "{\n "
272- const singleBracketWithSpaceAfter = '{ ' ;
273-
274- // Check it the entity is a bracket with no space after it
275- const isOnlySingleBracket = entity === singleBracket ;
276-
277- console . log ( { entity, isOnlySingleBracket, lastStringEntity } ) ;
278-
279- // If there is no space after it then remove it
280- if ( isOnlySingleBracket ) {
281- console . log ( { entity } ) ;
282- // save this entity as the last entity so that we can check if this directly follows another bracket
283- lastStringEntity = entity ;
284- return '' ;
285- }
286-
287- // Check if the entity is a bracket with a space after it and if a empty bracket was the last entity before it e.g. "{{ "
288- const isSingleBracketWithSpace =
289- entity === singleBracketWithSpaceAfter &&
290- lastStringEntity === singleBracket ;
291-
292- // If the entity is a bracket with a space after it and a single bracket was the last entity before it then remove it
293- if ( isSingleBracketWithSpace ) {
294- lastStringEntity = entity ;
295- return '' ;
296- }
297- }
283+ }
284+ // } else if (bracketArray.some(sub => entity.includes(sub))) {
285+ // // The plugin returns {{ testing }} like this:
286+ // // entity: "{"
287+ // // entity: "{ "
288+ // // entity: "testing }} "
289+
290+ // if (entity.includes('{')) {
291+ // // This is a bracket that has no space after it, meaning there is a string directly after it e.g. "{{"
292+ // const singleBracket = '{';
293+
294+ // // This is a bracket with a space after it and without a new line e.g. "{\n "
295+ // const singleBracketWithSpaceAfter = '{ ';
296+
297+ // // Check it the entity is a bracket with no space after it
298+ // const isOnlySingleBracket = entity === singleBracket;
299+
300+ // // console.log({ entity, isOnlySingleBracket, lastStringEntity });
301+
302+ // // If there is no space after it then remove it
303+ // if (isOnlySingleBracket) {
304+ // // console.log({ entity });
305+ // // save this entity as the last entity so that we can check if this directly follows another bracket
306+ // lastStringEntity = entity;
307+ // return '';
308+ // }
298309
299- // If this entity has double brackets then remove them and add a special class to it e.g. 'testing }}'
300- const cleanedEntity = entity . replace ( ' }}' , '' ) ;
310+ // // Check if the entity is a bracket with a space after it and if a empty bracket was the last entity before it e.g. "{{ "
311+ // const isSingleBracketWithSpace =
312+ // entity === singleBracketWithSpaceAfter &&
313+ // lastStringEntity === singleBracket;
301314
302- return {
303- kind : generateKindClassName ( `special ${ prefix } special__${ count ++ } ` ) ,
304- children : [ cleanedEntity ] ,
305- } ;
306- } else {
315+ // // If the entity is a bracket with a space after it and a single bracket was the last entity before it then remove it
316+ // if (isSingleBracketWithSpace) {
317+ // lastStringEntity = entity;
318+ // return '';
319+ // }
320+ // }
321+
322+ // // If this entity has double brackets then remove them and add a special class to it e.g. 'testing }}'
323+ // const cleanedEntity = entity.replace(' }}', '');
324+
325+ // return {
326+ // kind: generateKindClassName(`special ${prefix}special__${count++}`),
327+ // children: [cleanedEntity],
328+ // };
329+ // }
330+ else {
307331 return entity ;
308332 }
309333 // return parentKinds.length > 0
@@ -392,8 +416,10 @@ export function treeToLines(
392416 lines [ currentLineIndex ] = [ ] ;
393417 } ;
394418
419+ console . log ( '🤡🤡🤡🤡' , { children } ) ;
420+
395421 flattenNestedTree ( children ) . forEach ( child => {
396- console . log ( { child } ) ;
422+ // console.log({ child });
397423
398424 // If the current element includes a line break, we need to handle it differently
399425 if ( containsLineBreak ( child ) ) {
@@ -427,9 +453,20 @@ export function treeToLines(
427453 }
428454 } ) ;
429455
430- console . log ( '🤡🤡' , { lines } ) ;
456+ // console.log('🤡🤡', { lines });
457+
458+ const mergedLines = lines . map ( line => {
459+ const mergedLine = mergeAsterisks ( line ) ;
460+
461+ console . log ( { line, mergedLine } ) ;
431462
432- return lines ;
463+ return mergedLine ;
464+ } ) ;
465+
466+ // console.log('🌈🌈🌈🌈', { mergedLines });
467+
468+ // return lines;
469+ return mergedLines ;
433470}
434471
435472interface TableContentProps {
@@ -507,11 +544,15 @@ export function TableContent({ lines }: TableContentProps) {
507544}
508545
509546const plugin : LeafyGreenHLJSPlugin = {
547+ 'before:highlight' : function ( result : LeafyGreenHighlightResult ) {
548+ console . log ( '🤡 before' , { result } ) ;
549+ } ,
510550 'after:highlight' : function ( result : LeafyGreenHighlightResult ) {
511551 // console.log('💚', { result });
512552
513553 const { rootNode } = result . _emitter ;
514554 // console.log(JSON.stringify(rootNode.children, null, 2));
555+ console . log ( { rootNode } ) ;
515556 result . react = < TableContent lines = { treeToLines ( rootNode . children ) } /> ;
516557
517558 // console.log('💚💚💚', { result: result.react });
0 commit comments