# All files / src/lib/markdown-it/highlight helper.ts

100% Statements 22/22
100% Branches 3/3
100% Functions 3/3
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    3725x
    33x
    33x
    33x
    33x

    25x

    12x
    2x

    13x

    10x
    10x

    10x
    13x
    13x

    7x
    7x

    6x
    6x

    10x

    10x

     export function splitCodeAndIndentation(code: string) {
      const codeStartIdx = code.search(/\S|$/);
      const indents = code.substring(0, codeStartIdx);
      const content = code.substring(codeStartIdx);
      return [indents, content];
    }

    export function collateAllIntervalsWithColors(
      boundsWithColors: Array<{ bounds: [number, number], color: string }>,
    ) {
      if (boundsWithColors.length === 0) {
        return [];
      }

      boundsWithColors.sort((a, b) => a.bounds[0] - b.bounds[0]);

      const merged: Array<{ bounds: [number, number], color: string }> = [];
      let current = boundsWithColors[0];

      for (let i = 1; i < boundsWithColors.length; i += 1) {
        const next = boundsWithColors[i];
        if (next.bounds[0] <= (current.bounds[1] - 1)) {
          // merge if overlap
          current.bounds[1] = Math.max(current.bounds[1], next.bounds[1]);
          current.color = next.color;
        } else {
          merged.push(current);
          current = next;
        }
      }

      // Add the last merged interval
      merged.push(current);

      return merged;
    }