Blame view

node_modules/markdown-it/lib/helpers/parse_link_title.js 1.05 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
45
46
47
48
49
50
51
52
53
  // Parse link title
  //
  'use strict';
  
  
  var unescapeAll = require('../common/utils').unescapeAll;
  
  
  module.exports = function parseLinkTitle(str, pos, max) {
    var code,
        marker,
        lines = 0,
        start = pos,
        result = {
          ok: false,
          pos: 0,
          lines: 0,
          str: ''
        };
  
    if (pos >= max) { return result; }
  
    marker = str.charCodeAt(pos);
  
    if (marker !== 0x22 /* " */ && marker !== 0x27 /* ' */ && marker !== 0x28 /* ( */) { return result; }
  
    pos++;
  
    // if opening marker is "(", switch it to closing marker ")"
    if (marker === 0x28) { marker = 0x29; }
  
    while (pos < max) {
      code = str.charCodeAt(pos);
      if (code === marker) {
        result.pos = pos + 1;
        result.lines = lines;
        result.str = unescapeAll(str.slice(start + 1, pos));
        result.ok = true;
        return result;
      } else if (code === 0x0A) {
        lines++;
      } else if (code === 0x5C /* \ */ && pos + 1 < max) {
        pos++;
        if (str.charCodeAt(pos) === 0x0A) {
          lines++;
        }
      }
  
      pos++;
    }
  
    return result;
  };