motion-markdown-it 8.4.1.1 → 9.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +43 -2
  3. data/lib/motion-markdown-it/common/entities.rb +3 -0
  4. data/lib/motion-markdown-it/common/simpleidn.rb +8 -9
  5. data/lib/motion-markdown-it/common/utils.rb +48 -8
  6. data/lib/motion-markdown-it/helpers/parse_link_destination.rb +5 -5
  7. data/lib/motion-markdown-it/helpers/parse_link_label.rb +1 -1
  8. data/lib/motion-markdown-it/helpers/parse_link_title.rb +3 -3
  9. data/lib/motion-markdown-it/parser_core.rb +3 -3
  10. data/lib/motion-markdown-it/ruler.rb +3 -3
  11. data/lib/motion-markdown-it/rules_block/blockquote.rb +8 -8
  12. data/lib/motion-markdown-it/rules_block/fence.rb +5 -3
  13. data/lib/motion-markdown-it/rules_block/heading.rb +4 -4
  14. data/lib/motion-markdown-it/rules_block/hr.rb +2 -2
  15. data/lib/motion-markdown-it/rules_block/html_block.rb +2 -1
  16. data/lib/motion-markdown-it/rules_block/lheading.rb +2 -1
  17. data/lib/motion-markdown-it/rules_block/list.rb +36 -12
  18. data/lib/motion-markdown-it/rules_block/reference.rb +13 -13
  19. data/lib/motion-markdown-it/rules_block/state_block.rb +13 -11
  20. data/lib/motion-markdown-it/rules_block/table.rb +8 -8
  21. data/lib/motion-markdown-it/rules_core/linkify.rb +1 -1
  22. data/lib/motion-markdown-it/rules_core/normalize.rb +2 -2
  23. data/lib/motion-markdown-it/rules_core/replacements.rb +1 -1
  24. data/lib/motion-markdown-it/rules_core/smartquotes.rb +5 -5
  25. data/lib/motion-markdown-it/rules_inline/autolink.rb +3 -2
  26. data/lib/motion-markdown-it/rules_inline/backticks.rb +8 -5
  27. data/lib/motion-markdown-it/rules_inline/balance_pairs.rb +13 -3
  28. data/lib/motion-markdown-it/rules_inline/emphasis.rb +1 -1
  29. data/lib/motion-markdown-it/rules_inline/entity.rb +6 -6
  30. data/lib/motion-markdown-it/rules_inline/escape.rb +3 -3
  31. data/lib/motion-markdown-it/rules_inline/html_inline.rb +5 -5
  32. data/lib/motion-markdown-it/rules_inline/image.rb +8 -8
  33. data/lib/motion-markdown-it/rules_inline/link.rb +7 -7
  34. data/lib/motion-markdown-it/rules_inline/newline.rb +4 -4
  35. data/lib/motion-markdown-it/rules_inline/state_inline.rb +7 -7
  36. data/lib/motion-markdown-it/rules_inline/strikethrough.rb +1 -1
  37. data/lib/motion-markdown-it/rules_inline/text.rb +2 -1
  38. data/lib/motion-markdown-it/rules_inline/text_collapse.rb +10 -2
  39. data/lib/motion-markdown-it/version.rb +1 -3
  40. data/lib/motion-markdown-it.rb +0 -1
  41. data/spec/spec_helper.rb +2 -1
  42. metadata +11 -13
  43. data/lib/motion-markdown-it/common/string.rb +0 -14
@@ -13,16 +13,16 @@ module MarkdownIt
13
13
  # if it's indented more than 3 spaces, it should be a code block
14
14
  return false if state.sCount[startLine] - state.blkIndent >= 4
15
15
 
16
- return false if state.src.charCodeAt(pos) != 0x5B # [
16
+ return false if charCodeAt(state.src, pos) != 0x5B # [
17
17
 
18
18
  # Simple check to quickly interrupt scan on [link](url) at the start of line.
19
19
  # Can be useful on practice: https://github.com/markdown-it/markdown-it/issues/54
20
20
  pos += 1
21
21
  while (pos < max)
22
- if (state.src.charCodeAt(pos) == 0x5D && # ]
23
- state.src.charCodeAt(pos - 1) != 0x5C) # \
22
+ if (charCodeAt(state.src, pos) == 0x5D && # ]
23
+ charCodeAt(state.src, pos - 1) != 0x5C) # \
24
24
  return false if (pos + 1 === max)
25
- return false if (state.src.charCodeAt(pos + 1) != 0x3A) # :
25
+ return false if (charCodeAt(state.src, pos + 1) != 0x3A) # :
26
26
  break
27
27
  end
28
28
  pos += 1
@@ -62,7 +62,7 @@ module MarkdownIt
62
62
 
63
63
  pos = 1
64
64
  while pos < max
65
- ch = str.charCodeAt(pos)
65
+ ch = charCodeAt(str, pos)
66
66
  if (ch == 0x5B ) # [
67
67
  return false
68
68
  elsif (ch == 0x5D) # ]
@@ -72,20 +72,20 @@ module MarkdownIt
72
72
  lines += 1
73
73
  elsif (ch == 0x5C) # \
74
74
  pos += 1
75
- if (pos < max && str.charCodeAt(pos) == 0x0A)
75
+ if (pos < max && charCodeAt(str, pos) == 0x0A)
76
76
  lines += 1
77
77
  end
78
78
  end
79
79
  pos += 1
80
80
  end
81
81
 
82
- return false if (labelEnd < 0 || str.charCodeAt(labelEnd + 1) != 0x3A) # :
82
+ return false if (labelEnd < 0 || charCodeAt(str, labelEnd + 1) != 0x3A) # :
83
83
 
84
84
  # [label]: destination 'title'
85
85
  # ^^^ skip optional whitespace here
86
86
  pos = labelEnd + 2
87
87
  while pos < max
88
- ch = str.charCodeAt(pos)
88
+ ch = charCodeAt(str, pos)
89
89
  if (ch == 0x0A)
90
90
  lines += 1
91
91
  elsif isSpace(ch)
@@ -114,7 +114,7 @@ module MarkdownIt
114
114
  # ^^^ skipping those spaces
115
115
  start = pos
116
116
  while (pos < max)
117
- ch = str.charCodeAt(pos)
117
+ ch = charCodeAt(str, pos)
118
118
  if (ch == 0x0A)
119
119
  lines += 1
120
120
  elsif isSpace(ch)
@@ -139,12 +139,12 @@ module MarkdownIt
139
139
 
140
140
  # skip trailing spaces until the rest of the line
141
141
  while pos < max
142
- ch = str.charCodeAt(pos)
142
+ ch = charCodeAt(str, pos)
143
143
  break if !isSpace(ch)
144
144
  pos += 1
145
145
  end
146
146
 
147
- if (pos < max && str.charCodeAt(pos) != 0x0A)
147
+ if (pos < max && charCodeAt(str, pos) != 0x0A)
148
148
  if (title)
149
149
  # garbage at the end of the line after title,
150
150
  # but it could still be a valid reference if we roll back
@@ -152,14 +152,14 @@ module MarkdownIt
152
152
  pos = destEndPos
153
153
  lines = destEndLineNo
154
154
  while pos < max
155
- ch = str.charCodeAt(pos)
155
+ ch = charCodeAt(str, pos)
156
156
  break if !isSpace(ch)
157
157
  pos += 1
158
158
  end
159
159
  end
160
160
  end
161
161
 
162
- if (pos < max && str.charCodeAt(pos) != 0x0A)
162
+ if (pos < max && charCodeAt(str, pos) != 0x0A)
163
163
  # garbage at the end of the line
164
164
  return false
165
165
  end
@@ -6,7 +6,7 @@ module MarkdownIt
6
6
  include MarkdownIt::Common::Utils
7
7
 
8
8
  attr_accessor :src, :md, :env, :tokens, :bMarks, :eMarks, :tShift, :sCount, :bsCount
9
- attr_accessor :blkIndent, :line, :lineMax, :tight, :parentType, :ddIndent
9
+ attr_accessor :blkIndent, :line, :lineMax, :tight, :parentType, :ddIndent, :listIndent
10
10
  attr_accessor :level, :result
11
11
 
12
12
  #------------------------------------------------------------------------------
@@ -39,12 +39,14 @@ module MarkdownIt
39
39
  @bsCount = []
40
40
 
41
41
  # block parser variables
42
- @blkIndent = 0 # required block content indent (for example, if we are in list)
42
+ @blkIndent = 0 # equired block content indent (for example, if we are
43
+ # inside a list, it would be positioned after list marker)
43
44
  @line = 0 # line index in src
44
45
  @lineMax = 0 # lines count
45
46
  @tight = false # loose/tight mode for lists
46
47
  @parentType = 'root' # if `list`, block parser stops on two newlines
47
48
  @ddIndent = -1 # indent of the current dd block (-1 if there isn't any)
49
+ @listIndent = -1 # indent of the current list block (-1 if there isn't any)
48
50
 
49
51
  # can be 'blockquote', 'list', 'root', 'paragraph' or 'reference'
50
52
  # used in lists to determine if they interrupt a paragraph
@@ -63,7 +65,7 @@ module MarkdownIt
63
65
  start = pos = indent = offset = 0
64
66
  len = s.length
65
67
  while pos < len
66
- ch = s.charCodeAt(pos)
68
+ ch = charCodeAt(s, pos)
67
69
 
68
70
  if !indent_found
69
71
  if isSpace(ch)
@@ -113,9 +115,9 @@ module MarkdownIt
113
115
  token = Token.new(type, tag, nesting)
114
116
  token.block = true
115
117
 
116
- @level -= 1 if nesting < 0
118
+ @level -= 1 if nesting < 0 # closing tag
117
119
  token.level = @level
118
- @level += 1 if nesting > 0
120
+ @level += 1 if nesting > 0 # opening tag
119
121
 
120
122
  @tokens.push(token)
121
123
  return token
@@ -140,7 +142,7 @@ module MarkdownIt
140
142
  def skipSpaces(pos)
141
143
  max = @src.length
142
144
  while pos < max
143
- ch = @src.charCodeAt(pos)
145
+ ch = charCodeAt(@src, pos)
144
146
  break if !isSpace(ch)
145
147
  pos += 1
146
148
  end
@@ -153,7 +155,7 @@ module MarkdownIt
153
155
  return pos if pos <= min
154
156
 
155
157
  while (pos > min)
156
- return pos + 1 if !isSpace(@src.charCodeAt(pos -= 1))
158
+ return pos + 1 if !isSpace(charCodeAt(@src, pos -= 1))
157
159
  end
158
160
  return pos
159
161
  end
@@ -163,7 +165,7 @@ module MarkdownIt
163
165
  def skipChars(pos, code)
164
166
  max = @src.length
165
167
  while pos < max
166
- break if (@src.charCodeAt(pos) != code)
168
+ break if (charCodeAt(@src, pos) != code)
167
169
  pos += 1
168
170
  end
169
171
  return pos
@@ -175,7 +177,7 @@ module MarkdownIt
175
177
  return pos if pos <= min
176
178
 
177
179
  while (pos > min)
178
- return (pos + 1) if code != @src.charCodeAt(pos -= 1)
180
+ return (pos + 1) if code != charCodeAt(@src, pos -= 1)
179
181
  end
180
182
  return pos
181
183
  end
@@ -202,7 +204,7 @@ module MarkdownIt
202
204
  end
203
205
 
204
206
  while first < last && lineIndent < indent
205
- ch = @src.charCodeAt(first)
207
+ ch = charCodeAt(@src, first)
206
208
 
207
209
  if isSpace(ch)
208
210
  if ch === 0x09
@@ -236,4 +238,4 @@ module MarkdownIt
236
238
 
237
239
  end
238
240
  end
239
- end
241
+ end
@@ -23,7 +23,7 @@ module MarkdownIt
23
23
  backTicked = false
24
24
  lastBackTick = 0
25
25
 
26
- ch = str.charCodeAt(pos)
26
+ ch = charCodeAt(str, pos)
27
27
 
28
28
  while (pos < max)
29
29
  if ch == 0x60 # `
@@ -54,10 +54,10 @@ module MarkdownIt
54
54
  backTicked = false
55
55
  pos = lastBackTick + 1
56
56
  end
57
- ch = str.charCodeAt(pos)
57
+ ch = charCodeAt(str, pos)
58
58
  end
59
59
 
60
- result.push(str.slice_to_end(lastPos))
60
+ result.push(str[lastPos..-1])
61
61
 
62
62
  return result
63
63
  end
@@ -82,12 +82,12 @@ module MarkdownIt
82
82
  pos = state.bMarks[nextLine] + state.tShift[nextLine]
83
83
  return false if (pos >= state.eMarks[nextLine])
84
84
 
85
- ch = state.src.charCodeAt(pos)
85
+ ch = charCodeAt(state.src, pos)
86
86
  pos += 1
87
87
  return false if (ch != 0x7C && ch != 0x2D && ch != 0x3A) # | or - or :
88
88
 
89
89
  while pos < state.eMarks[nextLine]
90
- ch = state.src.charCodeAt(pos)
90
+ ch = charCodeAt(state.src, pos)
91
91
  return false if (ch != 0x7C && ch != 0x2D && ch != 0x3A && !isSpace(ch)) # | or - or :
92
92
 
93
93
  pos += 1
@@ -110,9 +110,9 @@ module MarkdownIt
110
110
  end
111
111
 
112
112
  return false if (/^:?-+:?$/ =~ t).nil?
113
- if (t.charCodeAt(t.length - 1) == 0x3A) # ':'
114
- aligns.push(t.charCodeAt(0) == 0x3A ? 'center' : 'right')
115
- elsif (t.charCodeAt(0) == 0x3A)
113
+ if (charCodeAt(t, t.length - 1) == 0x3A) # ':'
114
+ aligns.push(charCodeAt(t, 0) == 0x3A ? 'center' : 'right')
115
+ elsif (charCodeAt(t, 0) == 0x3A)
116
116
  aligns.push('left')
117
117
  else
118
118
  aligns.push('')
@@ -117,7 +117,7 @@ module MarkdownIt
117
117
  end
118
118
  if (lastPos < text.length)
119
119
  token = Token.new('text', '', 0)
120
- token.content = text.slice_to_end(lastPos)
120
+ token.content = text[lastPos..-1]
121
121
  token.level = level
122
122
  nodes.push(token)
123
123
  end
@@ -8,7 +8,7 @@ module MarkdownIt
8
8
  NULL_RE = /\u0000/
9
9
 
10
10
  #------------------------------------------------------------------------------
11
- def self.inline(state)
11
+ def self.normalize(state)
12
12
  # Normalize newlines
13
13
  str = state.src.gsub(NEWLINES_RE, "\n")
14
14
 
@@ -19,4 +19,4 @@ module MarkdownIt
19
19
  end
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -1,4 +1,4 @@
1
- # Simple typographyc replacements
1
+ # Simple typographic replacements
2
2
  #
3
3
  # (c) (C) → ©
4
4
  # (tm) (TM) → ™
@@ -11,7 +11,7 @@ module MarkdownIt
11
11
 
12
12
  #------------------------------------------------------------------------------
13
13
  def self.replaceAt(str, index, ch)
14
- return str[0, index] + ch + str.slice_to_end(index + 1)
14
+ return str[0, index] + ch + str[(index + 1)..-1]
15
15
  end
16
16
 
17
17
  #------------------------------------------------------------------------------
@@ -55,13 +55,13 @@ module MarkdownIt
55
55
  lastChar = 0x20
56
56
 
57
57
  if t.begin(0) - 1 >= 0
58
- lastChar = text.charCodeAt(t.begin(0) - 1)
58
+ lastChar = charCodeAt(text, t.begin(0) - 1)
59
59
  else
60
60
  (i - 1).downto(0) do |j|
61
61
  break if tokens[j].type == 'softbreak' || tokens[j].type == 'hardbreak' # lastChar defaults to 0x20
62
62
  next if tokens[j].type != 'text'
63
63
 
64
- lastChar = tokens[j].content.charCodeAt(tokens[j].content.length - 1)
64
+ lastChar = charCodeAt(tokens[j].content, tokens[j].content.length - 1)
65
65
  break
66
66
  end
67
67
  end
@@ -72,13 +72,13 @@ module MarkdownIt
72
72
  nextChar = 0x20
73
73
 
74
74
  if pos < max
75
- nextChar = text.charCodeAt(pos)
75
+ nextChar = charCodeAt(text, pos)
76
76
  else
77
77
  (i + 1).upto(tokens.length - 1) do |j|
78
78
  break if tokens[j].type == 'softbreak' || tokens[j].type == 'hardbreak' # nextChar defaults to 0x20
79
79
  next if tokens[j].type != 'text'
80
80
 
81
- nextChar = tokens[j].content.charCodeAt(0)
81
+ nextChar = charCodeAt(tokens[j].content, 0)
82
82
  break
83
83
  end
84
84
  end
@@ -3,6 +3,7 @@
3
3
  module MarkdownIt
4
4
  module RulesInline
5
5
  class Autolink
6
+ extend Common::Utils
6
7
 
7
8
  EMAIL_RE = /^<([a-zA-Z0-9.!#$\%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/
8
9
  AUTOLINK_RE = /^<([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)>/
@@ -11,9 +12,9 @@ module MarkdownIt
11
12
  def self.autolink(state, silent)
12
13
  pos = state.pos
13
14
 
14
- return false if (state.src.charCodeAt(pos) != 0x3C) # <
15
+ return false if (charCodeAt(state.src, pos) != 0x3C) # <
15
16
 
16
- tail = state.src.slice_to_end(pos)
17
+ tail = state.src[pos..-1]
17
18
 
18
19
  return false if !tail.include?('>')
19
20
 
@@ -3,19 +3,20 @@
3
3
  module MarkdownIt
4
4
  module RulesInline
5
5
  class Backticks
6
+ extend Common::Utils
6
7
 
7
8
  #------------------------------------------------------------------------------
8
9
  def self.backtick(state, silent)
9
10
  pos = state.pos
10
- ch = state.src.charCodeAt(pos)
11
+ ch = charCodeAt(state.src, pos)
11
12
 
12
- return false if (ch != 0x60) # `
13
+ return false if (ch != 0x60) # `
13
14
 
14
15
  start = pos
15
16
  pos += 1
16
17
  max = state.posMax
17
18
 
18
- while (pos < max && state.src.charCodeAt(pos) == 0x60) # `
19
+ while (pos < max && charCodeAt(state.src, pos) == 0x60) # `
19
20
  pos += 1
20
21
  end
21
22
 
@@ -26,7 +27,7 @@ module MarkdownIt
26
27
  while ((matchStart = state.src.index('`', matchEnd)) != nil)
27
28
  matchEnd = matchStart + 1
28
29
 
29
- while (matchEnd < max && state.src.charCodeAt(matchEnd) == 0x60) # `
30
+ while (matchEnd < max && charCodeAt(state.src, matchEnd) == 0x60) # `
30
31
  matchEnd += 1
31
32
  end
32
33
 
@@ -34,7 +35,9 @@ module MarkdownIt
34
35
  if (!silent)
35
36
  token = state.push('code_inline', 'code', 0)
36
37
  token.markup = marker
37
- token.content = state.src.slice(pos...matchStart).gsub(/[ \n]+/, ' ').strip
38
+ token.content = state.src.slice(pos...matchStart)
39
+ .gsub(/\n/, ' ')
40
+ .gsub(/^ (.+) $/, '\1')
38
41
  end
39
42
  state.pos = matchEnd
40
43
  return true
@@ -24,11 +24,21 @@ module MarkdownIt
24
24
  currDelim[:end] < 0 &&
25
25
  currDelim[:level] == lastDelim[:level]
26
26
 
27
+ odd_match = false
28
+
27
29
  # typeofs are for backward compatibility with plugins
28
30
  # not needed: typeof currDelim.length !== 'undefined' &&
29
31
  # typeof lastDelim.length !== 'undefined' &&
30
- odd_match = (currDelim[:close] || lastDelim[:open]) &&
31
- (currDelim[:length] + lastDelim[:length]) % 3 == 0
32
+ if (currDelim[:close] || lastDelim[:open])
33
+ # from spec:
34
+ # sum of the lengths [...] must not be a multiple of 3
35
+ # unless both lengths are multiples of 3
36
+ if ((currDelim[:length] + lastDelim[:length]) % 3) == 0
37
+ if (currDelim[:length] % 3 != 0 || lastDelim[:length] % 3 != 0)
38
+ odd_match = true
39
+ end
40
+ end
41
+ end
32
42
 
33
43
  if !odd_match
34
44
  lastDelim[:jump] = i - j
@@ -45,4 +55,4 @@ module MarkdownIt
45
55
  end
46
56
  end
47
57
  end
48
- end
58
+ end
@@ -9,7 +9,7 @@ module MarkdownIt
9
9
  #
10
10
  def self.tokenize(state, silent)
11
11
  start = state.pos
12
- marker = state.src.charCodeAt(start)
12
+ marker = charCodeAt(state.src, start)
13
13
 
14
14
  return false if silent
15
15
 
@@ -5,7 +5,7 @@ module MarkdownIt
5
5
  class Entity
6
6
  extend Common::Utils
7
7
 
8
- DIGITAL_RE = /^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i
8
+ DIGITAL_RE = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i
9
9
  NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i
10
10
 
11
11
 
@@ -14,23 +14,23 @@ module MarkdownIt
14
14
  pos = state.pos
15
15
  max = state.posMax
16
16
 
17
- return false if state.src.charCodeAt(pos) != 0x26 # &
17
+ return false if charCodeAt(state.src, pos) != 0x26 # &
18
18
 
19
19
  if pos + 1 < max
20
- ch = state.src.charCodeAt(pos + 1)
20
+ ch = charCodeAt(state.src, pos + 1)
21
21
 
22
22
  if ch == 0x23 # '#'
23
- match = state.src.slice_to_end(pos).match(DIGITAL_RE)
23
+ match = state.src[pos..-1].match(DIGITAL_RE)
24
24
  if match
25
25
  if !silent
26
- code = match[1][0].downcase == 'x' ? match[1].slice_to_end(1).to_i(16) : match[1].to_i
26
+ code = match[1][0].downcase == 'x' ? match[1][1..-1].to_i(16) : match[1].to_i
27
27
  state.pending += isValidEntityCode(code) ? fromCodePoint(code) : fromCodePoint(0xFFFD)
28
28
  end
29
29
  state.pos += match[0].length
30
30
  return true
31
31
  end
32
32
  else
33
- match = state.src.slice_to_end(pos).match(NAMED_RE)
33
+ match = state.src[pos..-1].match(NAMED_RE)
34
34
  if match
35
35
  if MarkdownIt::HTMLEntities::MAPPINGS[match[1]]
36
36
  state.pending += fromCodePoint(MarkdownIt::HTMLEntities::MAPPINGS[match[1]]) if !silent
@@ -17,12 +17,12 @@ module MarkdownIt
17
17
  pos = state.pos
18
18
  max = state.posMax
19
19
 
20
- return false if state.src.charCodeAt(pos) != 0x5C # \
20
+ return false if charCodeAt(state.src, pos) != 0x5C # \
21
21
 
22
22
  pos += 1
23
23
 
24
24
  if pos < max
25
- ch = state.src.charCodeAt(pos)
25
+ ch = charCodeAt(state.src, pos)
26
26
 
27
27
  if ch < 256 && ESCAPED[ch] != 0
28
28
  state.pending += state.src[pos] if !silent
@@ -38,7 +38,7 @@ module MarkdownIt
38
38
  pos += 1
39
39
  # skip leading whitespaces from next line
40
40
  while pos < max
41
- ch = state.src.charCodeAt(pos)
41
+ ch = charCodeAt(state.src, pos)
42
42
  break if !isSpace(ch)
43
43
  pos += 1
44
44
  end
@@ -1,11 +1,11 @@
1
1
  # Process html tags
2
2
  #------------------------------------------------------------------------------
3
3
  module MarkdownIt
4
-
5
4
  module RulesInline
6
5
  class HtmlInline
6
+ extend Common::Utils
7
7
  include MarkdownIt::Common::HtmlRe
8
-
8
+
9
9
  #------------------------------------------------------------------------------
10
10
  def self.isLetter(ch)
11
11
  lc = ch | 0x20 # to lower case
@@ -20,12 +20,12 @@ module MarkdownIt
20
20
 
21
21
  # Check start
22
22
  max = state.posMax
23
- if (state.src.charCodeAt(pos) != 0x3C || pos + 2 >= max) # <
23
+ if (charCodeAt(state.src, pos) != 0x3C || pos + 2 >= max) # <
24
24
  return false
25
25
  end
26
26
 
27
27
  # Quick fail on second char
28
- ch = state.src.charCodeAt(pos + 1)
28
+ ch = charCodeAt(state.src, pos + 1)
29
29
  if (ch != 0x21 && # !
30
30
  ch != 0x3F && # ?
31
31
  ch != 0x2F && # /
@@ -33,7 +33,7 @@ module MarkdownIt
33
33
  return false
34
34
  end
35
35
 
36
- match = state.src.slice_to_end(pos).match(HTML_TAG_RE)
36
+ match = state.src[pos..-1].match(HTML_TAG_RE)
37
37
  return false if !match
38
38
 
39
39
  if !silent
@@ -11,8 +11,8 @@ module MarkdownIt
11
11
  oldPos = state.pos
12
12
  max = state.posMax
13
13
 
14
- return false if (state.src.charCodeAt(state.pos) != 0x21) # !
15
- return false if (state.src.charCodeAt(state.pos + 1) != 0x5B) # [
14
+ return false if (charCodeAt(state.src, state.pos) != 0x21) # !
15
+ return false if (charCodeAt(state.src, state.pos + 1) != 0x5B) # [
16
16
 
17
17
  labelStart = state.pos + 2
18
18
  labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false)
@@ -21,7 +21,7 @@ module MarkdownIt
21
21
  return false if (labelEnd < 0)
22
22
 
23
23
  pos = labelEnd + 1
24
- if (pos < max && state.src.charCodeAt(pos) == 0x28) # (
24
+ if (pos < max && charCodeAt(state.src, pos) == 0x28) # (
25
25
  #
26
26
  # Inline link
27
27
  #
@@ -30,7 +30,7 @@ module MarkdownIt
30
30
  # ^^ skipping these spaces
31
31
  pos += 1
32
32
  while pos < max
33
- code = state.src.charCodeAt(pos)
33
+ code = charCodeAt(state.src, pos)
34
34
  break if (!isSpace(code) && code != 0x0A)
35
35
  pos += 1
36
36
  end
@@ -53,7 +53,7 @@ module MarkdownIt
53
53
  # ^^ skipping these spaces
54
54
  start = pos
55
55
  while pos < max
56
- code = state.src.charCodeAt(pos)
56
+ code = charCodeAt(state.src, pos)
57
57
  break if (!isSpace(code) && code != 0x0A)
58
58
  pos += 1
59
59
  end
@@ -68,7 +68,7 @@ module MarkdownIt
68
68
  # [link]( <href> "title" )
69
69
  # ^^ skipping these spaces
70
70
  while pos < max
71
- code = state.src.charCodeAt(pos);
71
+ code = charCodeAt(state.src, pos);
72
72
  break if (!isSpace(code) && code != 0x0A)
73
73
  pos += 1
74
74
  end
@@ -76,7 +76,7 @@ module MarkdownIt
76
76
  title = ''
77
77
  end
78
78
 
79
- if (pos >= max || state.src.charCodeAt(pos) != 0x29) # )
79
+ if (pos >= max || charCodeAt(state.src, pos) != 0x29) # )
80
80
  state.pos = oldPos
81
81
  return false
82
82
  end
@@ -87,7 +87,7 @@ module MarkdownIt
87
87
  #
88
88
  return false if state.env[:references].nil?
89
89
 
90
- if (pos < max && state.src.charCodeAt(pos) == 0x5B) # [
90
+ if (pos < max && charCodeAt(state.src, pos) == 0x5B) # [
91
91
  start = pos + 1
92
92
  pos = state.md.helpers.parseLinkLabel(state, pos)
93
93
  if (pos >= 0)
@@ -13,7 +13,7 @@ module MarkdownIt
13
13
  start = state.pos
14
14
  parseReference = true
15
15
 
16
- return false if (state.src.charCodeAt(state.pos) != 0x5B) # [
16
+ return false if (charCodeAt(state.src, state.pos) != 0x5B) # [
17
17
 
18
18
  labelStart = state.pos + 1
19
19
  labelEnd = state.md.helpers.parseLinkLabel(state, state.pos, true)
@@ -22,7 +22,7 @@ module MarkdownIt
22
22
  return false if (labelEnd < 0)
23
23
 
24
24
  pos = labelEnd + 1
25
- if (pos < max && state.src.charCodeAt(pos) == 0x28) # (
25
+ if (pos < max && charCodeAt(state.src, pos) == 0x28) # (
26
26
  #
27
27
  # Inline link
28
28
  #
@@ -34,7 +34,7 @@ module MarkdownIt
34
34
  # ^^ skipping these spaces
35
35
  pos += 1
36
36
  while pos < max
37
- code = state.src.charCodeAt(pos)
37
+ code = charCodeAt(state.src, pos)
38
38
  break if (!isSpace(code) && code != 0x0A)
39
39
  pos += 1
40
40
  end
@@ -57,7 +57,7 @@ module MarkdownIt
57
57
  # ^^ skipping these spaces
58
58
  start = pos
59
59
  while pos < max
60
- code = state.src.charCodeAt(pos)
60
+ code = charCodeAt(state.src, pos)
61
61
  break if (!isSpace(code) && code != 0x0A)
62
62
  pos += 1
63
63
  end
@@ -72,7 +72,7 @@ module MarkdownIt
72
72
  # [link]( <href> "title" )
73
73
  # ^^ skipping these spaces
74
74
  while pos < max
75
- code = state.src.charCodeAt(pos)
75
+ code = charCodeAt(state.src, pos)
76
76
  break if (!isSpace(code) && code != 0x0A)
77
77
  pos += 1
78
78
  end
@@ -80,7 +80,7 @@ module MarkdownIt
80
80
  title = ''
81
81
  end
82
82
 
83
- if (pos >= max || state.src.charCodeAt(pos) != 0x29) # )
83
+ if (pos >= max || charCodeAt(state.src, pos) != 0x29) # )
84
84
  # parsing a valid shortcut link failed, fallback to reference
85
85
  parseReference = true
86
86
  end
@@ -93,7 +93,7 @@ module MarkdownIt
93
93
  #
94
94
  return false if state.env[:references].nil?
95
95
 
96
- if (pos < max && state.src.charCodeAt(pos) == 0x5B) # [
96
+ if (pos < max && charCodeAt(state.src, pos) == 0x5B) # [
97
97
  start = pos + 1
98
98
  pos = state.md.helpers.parseLinkLabel(state, pos)
99
99
  if (pos >= 0)
@@ -8,7 +8,7 @@ module MarkdownIt
8
8
  #------------------------------------------------------------------------------
9
9
  def self.newline(state, silent)
10
10
  pos = state.pos
11
- return false if state.src.charCodeAt(pos) != 0x0A # \n
11
+ return false if charCodeAt(state.src, pos) != 0x0A # \n
12
12
 
13
13
  pmax = state.pending.length - 1
14
14
  max = state.posMax
@@ -18,8 +18,8 @@ module MarkdownIt
18
18
  # Pending string is stored in concat mode, indexed lookups will cause
19
19
  # convertion to flat mode.
20
20
  if !silent
21
- if pmax >= 0 && state.pending.charCodeAt(pmax) == 0x20
22
- if pmax >= 1 && state.pending.charCodeAt(pmax - 1) == 0x20
21
+ if pmax >= 0 && charCodeAt(state.pending, pmax) == 0x20
22
+ if pmax >= 1 && charCodeAt(state.pending, pmax - 1) == 0x20
23
23
  state.pending = state.pending.sub(/ +$/, '')
24
24
  state.push('hardbreak', 'br', 0)
25
25
  else
@@ -35,7 +35,7 @@ module MarkdownIt
35
35
  pos += 1
36
36
 
37
37
  # skip heading spaces for next line
38
- while pos < max && isSpace(state.src.charCodeAt(pos))
38
+ while pos < max && isSpace(charCodeAt(state.src, pos))
39
39
  pos += 1
40
40
  end
41
41