Skip to content

Commit 952fb3f

Browse files
Merge pull request #4 from digitalmoksha/sync-with-9.0.0
Sync from 8.4.1 to 9.0.1
2 parents 677bdf1 + 7f17d63 commit 952fb3f

File tree

24 files changed

+1566
-850
lines changed

24 files changed

+1566
-850
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
9.0.1
2+
-------
3+
4+
Synced with markdown-it 9.0.1, see the [CHANGELOG](https://github.com/markdown-it/markdown-it/blob/master/CHANGELOG.md)
5+
16
8.4.1
27
-------
38

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ gem 'kramdown', require: 'kramdown'
77
gem 'commonmarker'
88
gem 'redcarpet'
99

10+
group :development, :test do
11+
gem 'pry-byebug'
12+
end
13+
1014
gemspec

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
Ruby/RubyMotion version of Markdown-it (CommonMark compliant and extendable)
77

8-
This gem is a port of the [markdown-it Javascript package](https://github.com/markdown-it/markdown-it) by Vitaly Puzrin and Alex Kocharin. Currently synced with markdown-it 8.4.1
8+
This gem is a port of the [markdown-it Javascript package](https://github.com/markdown-it/markdown-it) by Vitaly Puzrin and Alex Kocharin.
9+
10+
_Currently synced with markdown-it 9.0.1_
911

1012
---
1113

lib/motion-markdown-it/common/entities.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module MarkdownIt
33

44
# TODO this list needs to be brought up to same level as the WC3 document
55
# http://www.w3.org/TR/xml-entity-names/byalpha.html
6+
# Consider pulling in https://github.com/fb55/entities/blob/master/maps/entities.json,
7+
# is kept up to date
68
#------------------------------------------------------------------------------
79
class HTMLEntities
810

@@ -626,6 +628,7 @@ class HTMLEntities
626628
'nearr' => 0x2197, # ↗ NORTH EAST ARROW
627629
'nequiv' => 0x2262, # ≢ NOT IDENTICAL TO
628630
'nexist' => 0x2204, # ∄ THERE DOES NOT EXIST
631+
'ngE' => '≧̸', # ≧̸ from https://github.com/fb55/entities/blob/master/maps/entities.json
629632
'nge' => 0x2271, # ≱ dup NEITHER GREATER-THAN NOR EQUAL TO
630633
'nges' => 0x2271, # ≱ dup skip NEITHER GREATER-THAN NOR EQUAL TO
631634
'Ngr' => 0x039d, # Ν dup skip GREEK CAPITAL LETTER NU

lib/motion-markdown-it/common/utils.rb

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ def isValidEntityCode(c)
4848

4949
#------------------------------------------------------------------------------
5050
def fromCodePoint(c)
51-
c.chr(Encoding::UTF_8)
51+
# Some html entities are mapped directly as characters rather than code points.
52+
# So if we're passed an Integer, convert to character, otherwise just return
53+
# the character. For example `≧̸`
54+
c.is_a?(Integer) ? c.chr(Encoding::UTF_8) : c
5255
end
5356

5457
#------------------------------------------------------------------------------
5558
def fromCharCode(c)
5659
c.chr
5760
end
58-
61+
5962
#------------------------------------------------------------------------------
6063
def charCodeAt(str, ch)
6164
str[ch].ord unless str[ch].nil?
@@ -216,11 +219,44 @@ def isMdAsciiPunct(ch)
216219
# Hepler to unify [reference labels].
217220
#------------------------------------------------------------------------------
218221
def normalizeReference(str)
219-
# use .toUpperCase() instead of .toLowerCase()
220-
# here to avoid a conflict with Object.prototype
221-
# members (most notably, `__proto__`)
222-
return str.strip.gsub(/\s+/, ' ').upcase
222+
# Trim and collapse whitespace
223+
#
224+
str = str.strip.gsub(/\s+/, ' ')
225+
226+
# .toLowerCase().toUpperCase() should get rid of all differences
227+
# between letter variants.
228+
#
229+
# Simple .toLowerCase() doesn't normalize 125 code points correctly,
230+
# and .toUpperCase doesn't normalize 6 of them (list of exceptions:
231+
# İ, ϴ, ẞ, Ω, K, Å - those are already uppercased, but have differently
232+
# uppercased versions).
233+
#
234+
# Here's an example showing how it happens. Lets take greek letter omega:
235+
# uppercase U+0398 (Θ), U+03f4 (ϴ) and lowercase U+03b8 (θ), U+03d1 (ϑ)
236+
#
237+
# Unicode entries:
238+
# 0398;GREEK CAPITAL LETTER THETA;Lu;0;L;;;;;N;;;;03B8;
239+
# 03B8;GREEK SMALL LETTER THETA;Ll;0;L;;;;;N;;;0398;;0398
240+
# 03D1;GREEK THETA SYMBOL;Ll;0;L;<compat> 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398
241+
# 03F4;GREEK CAPITAL THETA SYMBOL;Lu;0;L;<compat> 0398;;;;N;;;;03B8;
242+
#
243+
# Case-insensitive comparison should treat all of them as equivalent.
244+
#
245+
# But .toLowerCase() doesn't change ϑ (it's already lowercase),
246+
# and .toUpperCase() doesn't change ϴ (already uppercase).
247+
#
248+
# Applying first lower then upper case normalizes any character:
249+
# '\u0398\u03f4\u03b8\u03d1'.toLowerCase().toUpperCase() === '\u0398\u0398\u0398\u0398'
250+
#
251+
# Note: this is equivalent to unicode case folding; unicode normalization
252+
# is a different step that is not required here.
253+
#
254+
# Final result should be uppercased, because it's later stored in an object
255+
# (this avoid a conflict with Object.prototype members,
256+
# most notably, `__proto__`)
257+
#
258+
return str.downcase.upcase
223259
end
224260
end
225261
end
226-
end
262+
end

lib/motion-markdown-it/helpers/parse_link_destination.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def parseLinkDestination(str, pos, max)
1515
pos += 1
1616
while (pos < max)
1717
code = charCodeAt(str, pos)
18-
return result if (code == 0x0A || isSpace(code)) # \n
18+
return result if (code == 0x0A) # \n
1919
if (code == 0x3E) # >
2020
result[:pos] = pos + 1
2121
result[:str] = unescapeAll(str.slice((start + 1)...pos))
@@ -73,4 +73,4 @@ def parseLinkDestination(str, pos, max)
7373
end
7474
end
7575
end
76-
end
76+
end

lib/motion-markdown-it/parser_core.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module MarkdownIt
88
class ParserCore
99

1010
attr_accessor :ruler
11-
11+
1212
RULES = [
13-
[ 'normalize', lambda { |state| RulesCore::Normalize.inline(state) } ],
13+
[ 'normalize', lambda { |state| RulesCore::Normalize.normalize(state) } ],
1414
[ 'block', lambda { |state| RulesCore::Block.block(state) } ],
1515
[ 'inline', lambda { |state| RulesCore::Inline.inline(state) } ],
1616
[ 'linkify', lambda { |state| RulesCore::Linkify.linkify(state) } ],
@@ -43,4 +43,4 @@ def process(state)
4343
end
4444
end
4545
end
46-
end
46+
end

lib/motion-markdown-it/ruler.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#------------------------------------------------------------------------------
1717

1818
module MarkdownIt
19-
class Ruler
19+
class Ruler
2020

2121
def initialize
2222
# // List of added rules. Each element is:
@@ -94,7 +94,7 @@ def __compile__
9494
# *
9595
# * ##### Example
9696
# *
97-
# * Replace existing typorgapher replacement rule with new one:
97+
# * Replace existing typographer replacement rule with new one:
9898
# *
9999
# * ```javascript
100100
# * var md = require('markdown-it')();
@@ -108,7 +108,7 @@ def at(name, fn, opt = {})
108108
index = __find__(name)
109109

110110
raise(StandardError, "Parser rule not found: #{name}") if index == -1
111-
111+
112112
@__rules__[index][:fn] = fn
113113
@__rules__[index][:alt] = opt[:alt] || ['']
114114
@__cache__ = nil

lib/motion-markdown-it/rules_block/fence.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def self.fence(state, startLine, endLine, silent)
3232
markup = state.src.slice(mem...pos)
3333
params = state.src.slice(pos...max)
3434

35-
return false if params.include?(fromCharCode(marker))
35+
if (marker == 0x60) # `
36+
return false if params.include?(fromCharCode(marker))
37+
end
3638

3739
# Since start is found, we can report success here in validation mode
3840
return true if silent

lib/motion-markdown-it/rules_block/list.rb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ def self.list(state, startLine, endLine, silent)
109109
# if it's indented more than 3 spaces, it should be a code block
110110
return false if (state.sCount[startLine] - state.blkIndent >= 4)
111111

112+
# Special case:
113+
# - item 1
114+
# - item 2
115+
# - item 3
116+
# - item 4
117+
# - this one is a paragraph continuation
118+
if (state.listIndent >= 0 &&
119+
state.sCount[startLine] - state.listIndent >= 4 &&
120+
state.sCount[startLine] < state.blkIndent)
121+
return false
122+
end
123+
112124
# limit conditions when list can interrupt
113125
# a paragraph (validation mode only)
114126
if silent && state.parentType == 'paragraph'
@@ -220,11 +232,19 @@ def self.list(state, startLine, endLine, silent)
220232
token.markup = markerCharCode.chr
221233
token.map = itemLines = [ startLine, 0 ]
222234

223-
oldIndent = state.blkIndent
235+
# change current state, then restore it after parser subcall
224236
oldTight = state.tight
225237
oldTShift = state.tShift[startLine]
226-
oldLIndent = state.sCount[startLine]
238+
oldSCount = state.sCount[startLine]
239+
240+
# - example list
241+
# ^ listIndent position will be here
242+
# ^ blkIndent position will be here
243+
#
244+
oldListIndent = state.listIndent
245+
state.listIndent = state.blkIndent
227246
state.blkIndent = indent
247+
228248
state.tight = true
229249
state.tShift[startLine] = contentStart - state.bMarks[startLine]
230250
state.sCount[startLine] = offset
@@ -250,9 +270,10 @@ def self.list(state, startLine, endLine, silent)
250270
# but we should filter last element, because it means list finish
251271
prevEmptyEnd = (state.line - startLine) > 1 && state.isEmpty(state.line - 1)
252272

253-
state.blkIndent = oldIndent
273+
state.blkIndent = state.listIndent
274+
state.listIndent = oldListIndent
254275
state.tShift[startLine] = oldTShift
255-
state.sCount[startLine] = oldLIndent
276+
state.sCount[startLine] = oldSCount
256277
state.tight = oldTight
257278

258279
token = state.push('list_item_close', 'li', -1)
@@ -269,6 +290,9 @@ def self.list(state, startLine, endLine, silent)
269290
#
270291
break if (state.sCount[nextLine] < state.blkIndent)
271292

293+
# if it's indented more than 3 spaces, it should be a code block
294+
break if (state.sCount[startLine] - state.blkIndent >= 4)
295+
272296
# fail if terminating block found
273297
terminate = false
274298
(0...terminatorRules.length).each do |i|

0 commit comments

Comments
 (0)