# All files / src/lib/markdown-it/utils index.ts

33.33% Statements 2/6
100% Branches 0/0
0% Functions 0/2
33.33% Lines 2/6

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

    8x

    8x

     /*
      Extra utility functions related to markdown-it.
      markdown-it library exposes a utility module in markdown-it/utils,
      below are additional functions that can be used as helpers alongside markdown-it/utils
     */

    // This mapping is taken from markdown-it/utils, just flipped.
    // Refer to the original file at markdown-it/lib/common/utils.js
    const htmlUnescapedMapping = {
      '&amp;': '&',
      '&lt;': '<',
      '&gt;': '>',
      '&quot;': '"',
      '&#x27;': '\'',
    };

    // markdown-it/utils have an escapeHtml function, but not the
    // complementary un-escaping function
    export function unescapeHtml(str: string) {
      let unescaped = str;
      Object.entries(htmlUnescapedMapping).forEach(([key, value]) => {
        unescaped = unescaped.split(key).join(value);
      });
      return unescaped;
    }