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

100% Statements 21/21
100% Branches 2/2
100% Functions 3/3
100% Lines 19/19

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

    29x
    44x
    44x
    44x
    44x

    29x
    10x
    14x
    10x
    10x
    10x
    14x
    14x
    4x

    10x
    10x
    10x

    10x
    10x

     // Common helper functions to be used in HighlightRule or HighlightRuleComponent

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

    // Simplifies and collates multiple bounds applied on a single line to an array of disjointed bounds
    // e.g. [[0, 2], [1, 3], [8, 10]] -> [[0, 3], [8, 10]]
    export function collateAllIntervals(bounds: Array<[number, number]>) {
      const output: Array<[number, number]> = [];
      bounds.sort((boundA, boundB) => boundA[0] - boundB[0]);
      let currStart = bounds[0][0];
      let currEnd = bounds[0][1];
      for (let i = 1; i < bounds.length; i += 1) {
        const [start, end] = bounds[i];
        if (start <= currEnd) {
          currEnd = Math.max(currEnd, end);
        } else {
          output.push([currStart, currEnd]);
          currStart = start;
          currEnd = end;
        }
      }
      output.push([currStart, currEnd]);
      return output;
    }