# All files / src/lib/markdown-it/patches/custom-component htmlInlineRule.js

17.39% Statements 4/23
0% Branches 0/18
0% Functions 0/2
17.39% Lines 4/23

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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    489x

    9x

    9x

    9x
     const { HTML_TAG_RE } = require('./htmlRe');

    // Forked and modified from 'markdown-it/lib/rules_inline/html_inline.js'

    const isLetter = (ch) => {
      const lc = ch | 0x20 // to lower case
      return lc >= 0x61 /* a */ && lc <= 0x7a /* z */
    }

    const htmlInlineRule = (state, silent) => {
      const pos = state.pos
      if (!state.md.options.html) {
        return false
      }

      // Check start
      const max = state.posMax
      if (state.src.charCodeAt(pos) !== 0x3c /* < */ || pos + 2 >= max) {
        return false
      }

      // Quick fail on second char
      const ch = state.src.charCodeAt(pos + 1)
      if (
        ch !== 0x21 /* ! */ &&
        ch !== 0x3f /* ? */ &&
        ch !== 0x2f /* / */ &&
        !isLetter(ch)
      ) {
        return false
      }

      // MODIFIED HERE: Tweak the original HTML_TAG_RE
      const match = state.src.slice(pos).match(HTML_TAG_RE)
      if (!match) {
        return false
      }

      if (!silent) {
        const token = state.push('html_inline', '', 0)
        token.content = state.src.slice(pos, pos + match[0].length)
      }
      state.pos += match[0].length
      return true
    }

    module.exports = htmlInlineRule;