Blame view

node_modules/markdown-it/lib/rules_inline/balance_pairs.js 1.13 KB
290144e9   易尊强   第一次
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
  // For each opening emphasis-like marker find a matching closing one
  //
  'use strict';
  
  
  module.exports = function link_pairs(state) {
    var i, j, lastDelim, currDelim,
        delimiters = state.delimiters,
        max = state.delimiters.length;
  
    for (i = 0; i < max; i++) {
      lastDelim = delimiters[i];
  
      if (!lastDelim.close) { continue; }
  
      j = i - lastDelim.jump - 1;
  
      while (j >= 0) {
        currDelim = delimiters[j];
  
        if (currDelim.open &&
            currDelim.marker === lastDelim.marker &&
            currDelim.end < 0 &&
            currDelim.level === lastDelim.level) {
  
          // typeofs are for backward compatibility with plugins
          var odd_match = (currDelim.close || lastDelim.open) &&
                          typeof currDelim.length !== 'undefined' &&
                          typeof lastDelim.length !== 'undefined' &&
                          (currDelim.length + lastDelim.length) % 3 === 0;
  
          if (!odd_match) {
            lastDelim.jump = i - j;
            lastDelim.open = false;
            currDelim.end  = i;
            currDelim.jump = 0;
            break;
          }
        }
  
        j -= currDelim.jump + 1;
      }
    }
  };