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

100% Statements 9/9
100% Branches 0/0
100% Functions 4/4
100% Lines 8/8

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
    2423x

    23x

    2x

    4x
    4x

    4x
    8x
    4x

     import { collateAllIntervals, splitCodeAndIndentation } from './helper';

    export class Highlighter {
      static highlightWholeLine(code: string) {
        return `<span class="highlighted">${code}\n</span>`;
      }

      static highlightWholeText(code: string) {
        const [indents, content] = splitCodeAndIndentation(code);
        return `<span>${indents}<span class="highlighted">${content}</span>\n</span>`;
      }

      static highlightPartOfText(code: string, bounds: Array<[number, number]>) {
        /*
          * Note: As part-of-text highlighting requires walking over the node of the generated
          * html by highlight.js, highlighting will be applied in NodeProcessor instead.
          * hl-data is used to pass over the bounds.
        */
        const mergedBounds = collateAllIntervals(bounds);
        const dataStr = mergedBounds.map(bound => bound.join('-')).join(',');
        return `<span hl-data=${dataStr}>${code}\n</span>`;
      }
    }