motion-markdown-it 4.2.2.0 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/motion-markdown-it.rb +1 -1
- data/lib/motion-markdown-it/common/html_blocks.rb +31 -24
- data/lib/motion-markdown-it/common/html_re.rb +2 -0
- data/lib/motion-markdown-it/renderer.rb +3 -2
- data/lib/motion-markdown-it/rules_block/html_block.rb +45 -42
- data/lib/motion-markdown-it/rules_block/list.rb +9 -3
- data/lib/motion-markdown-it/rules_block/reference.rb +13 -0
- data/lib/motion-markdown-it/version.rb +1 -1
- data/spec/motion-markdown-it/bench_mark_spec.rb +44 -44
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb7bc35a96283f575397326f35cc15789b4700fe
|
4
|
+
data.tar.gz: feacd41709859ddb7b8fd30f288af2a53c80c562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d64baed7b2ed7ecadc4b3a31b9d723502ab564e08871401b0d9b2d7dfeb017e12c09656692639f6d1b5dc911a0cc4605c8d832181e2c5b05c43d0e725c6edec0
|
7
|
+
data.tar.gz: 6dc2d585c57113b580d398c9370db04a22c7cb8c8470af53857c8a1b5df67601368c4aa557cf4b791201a3cef7e1a7d063190857d059f24508a546d6b77ac874
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# motion-markdown-it
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/motion-markdown-it.svg)](http://badge.fury.io/rb/motion-markdown-it)
|
4
|
+
[![Build Status](https://travis-ci.org/digitalmoksha/motion-markdown-it.svg?branch=master)](https://travis-ci.org/digitalmoksha/motion-markdown-it)
|
4
5
|
|
6
|
+
https://travis-ci.org/digitalmoksha/motion-markdown-it.svg?branch=master
|
5
7
|
Ruby/RubyMotion version of Markdown-it (CommonMark compliant and extendable)
|
6
8
|
|
7
|
-
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 4.
|
9
|
+
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 4.4.0
|
8
10
|
|
9
11
|
__[Javascript Live demo](https://markdown-it.github.io)__
|
10
12
|
|
@@ -22,7 +24,7 @@ The benefit of this project, for me at least, is to have a standardized CommonMa
|
|
22
24
|
|
23
25
|
## Performance
|
24
26
|
|
25
|
-
Performance is still an issue. While it performs reasonably well with small to medium files, it degrades for large files. Work in
|
27
|
+
Performance is still an issue. While it performs reasonably well with small to medium files, it degrades for large files. Work in progress...
|
26
28
|
|
27
29
|
## Table of content
|
28
30
|
|
data/lib/motion-markdown-it.rb
CHANGED
@@ -2,59 +2,66 @@
|
|
2
2
|
# http://jgm.github.io/CommonMark/spec.html#html-blocks
|
3
3
|
#------------------------------------------------------------------------------
|
4
4
|
module MarkdownIt
|
5
|
-
HTML_BLOCKS =
|
6
|
-
|
7
|
-
[
|
5
|
+
HTML_BLOCKS = [
|
6
|
+
'address',
|
8
7
|
'article',
|
9
8
|
'aside',
|
10
|
-
'
|
9
|
+
'base',
|
10
|
+
'basefont',
|
11
11
|
'blockquote',
|
12
12
|
'body',
|
13
|
-
'canvas',
|
14
13
|
'caption',
|
14
|
+
'center',
|
15
15
|
'col',
|
16
16
|
'colgroup',
|
17
17
|
'dd',
|
18
|
+
'details',
|
19
|
+
'dialog',
|
20
|
+
'dir',
|
18
21
|
'div',
|
19
22
|
'dl',
|
20
23
|
'dt',
|
21
|
-
'embed',
|
22
24
|
'fieldset',
|
23
25
|
'figcaption',
|
24
26
|
'figure',
|
25
27
|
'footer',
|
26
28
|
'form',
|
29
|
+
'frame',
|
30
|
+
'frameset',
|
27
31
|
'h1',
|
28
|
-
'
|
29
|
-
'h3',
|
30
|
-
'h4',
|
31
|
-
'h5',
|
32
|
-
'h6',
|
32
|
+
'head',
|
33
33
|
'header',
|
34
|
-
'hgroup',
|
35
34
|
'hr',
|
36
|
-
'
|
35
|
+
'html',
|
36
|
+
'legend',
|
37
37
|
'li',
|
38
|
-
'
|
39
|
-
'
|
38
|
+
'link',
|
39
|
+
'main',
|
40
|
+
'menu',
|
41
|
+
'menuitem',
|
42
|
+
'meta',
|
43
|
+
'nav',
|
44
|
+
'noframes',
|
40
45
|
'ol',
|
41
|
-
'
|
46
|
+
'optgroup',
|
47
|
+
'option',
|
42
48
|
'p',
|
49
|
+
'param',
|
43
50
|
'pre',
|
44
|
-
'progress',
|
45
|
-
'script',
|
46
51
|
'section',
|
47
|
-
'
|
52
|
+
'source',
|
53
|
+
'title',
|
54
|
+
'summary',
|
48
55
|
'table',
|
49
56
|
'tbody',
|
50
57
|
'td',
|
51
|
-
'textarea',
|
52
58
|
'tfoot',
|
53
59
|
'th',
|
54
|
-
'tr',
|
55
60
|
'thead',
|
56
|
-
'
|
57
|
-
'
|
58
|
-
|
61
|
+
'title',
|
62
|
+
'tr',
|
63
|
+
'track',
|
64
|
+
'ul'
|
65
|
+
].freeze
|
59
66
|
|
60
67
|
end
|
@@ -23,6 +23,8 @@ module MarkdownIt
|
|
23
23
|
|
24
24
|
HTML_TAG_RE = Regexp.new('^(?:' + OPEN_TAG + '|' + CLOSE_TAG + '|' + COMMENT +
|
25
25
|
'|' + PROCESSING + '|' + DECLARATION + '|' + CDATA + ')')
|
26
|
+
|
27
|
+
HTML_OPEN_CLOSE_TAG_RE = Regexp.new('^(?:' + OPEN_TAG + '|' + CLOSE_TAG + ')')
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -25,10 +25,11 @@ module MarkdownIt
|
|
25
25
|
#------------------------------------------------------------------------------
|
26
26
|
def self.fence(tokens, idx, options, env, renderer)
|
27
27
|
token = tokens[idx]
|
28
|
+
info = token.info ? unescapeAll(token.info).strip : ''
|
28
29
|
langName = ''
|
29
30
|
|
30
|
-
if !
|
31
|
-
langName =
|
31
|
+
if !info.empty?
|
32
|
+
langName = info.split(/\s+/)[0]
|
32
33
|
token.attrPush([ 'class', options[:langPrefix] + langName ])
|
33
34
|
end
|
34
35
|
|
@@ -4,66 +4,69 @@ module MarkdownIt
|
|
4
4
|
module RulesBlock
|
5
5
|
class HtmlBlock
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
HTML_OPEN_CLOSE_TAG_RE = MarkdownIt::Common::HtmlRe::HTML_OPEN_CLOSE_TAG_RE
|
8
|
+
|
9
|
+
# An array of opening and corresponding closing sequences for html tags,
|
10
|
+
# last argument defines whether it can terminate a paragraph or not
|
11
|
+
#
|
12
|
+
HTML_SEQUENCES = [
|
13
|
+
[ /^<(script|pre|style)(?=(\s|>|$))/i, /<\/(script|pre|style)>/i, true ],
|
14
|
+
[ /^<!--/, /-->/, true ],
|
15
|
+
[ /^<\?/, /\?>/, true ],
|
16
|
+
[ /^<![A-Z]/, />/, true ],
|
17
|
+
[ /^<!\[CDATA\[/, /\]\]>/, true ],
|
18
|
+
[ Regexp.new('^</?(' + MarkdownIt::HTML_BLOCKS.join('|') + ')(?=(\\s|/?>|$))', 'i'), /^$/, true ],
|
19
|
+
[ Regexp.new(HTML_OPEN_CLOSE_TAG_RE.source + '\\s*$'), /^$/, false ]
|
20
|
+
];
|
15
21
|
|
16
22
|
#------------------------------------------------------------------------------
|
17
23
|
def self.html_block(state, startLine, endLine, silent)
|
18
|
-
pos = state.bMarks[startLine]
|
24
|
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
19
25
|
max = state.eMarks[startLine]
|
20
|
-
shift = state.tShift[startLine]
|
21
|
-
|
22
|
-
pos += shift
|
23
26
|
|
24
27
|
return false if !state.md.options[:html]
|
25
|
-
return false if shift > 3 || (pos + 2) >= max
|
26
28
|
return false if state.src.charCodeAt(pos) != 0x3C # <
|
27
29
|
|
28
|
-
|
30
|
+
lineText = state.src.slice(pos...max)
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if ch == 0x2F # \
|
38
|
-
# closing tag
|
39
|
-
match = state.src.slice(pos...max).match(HTML_TAG_CLOSE_RE)
|
40
|
-
return false if (!match)
|
41
|
-
else
|
42
|
-
# opening tag
|
43
|
-
match = state.src.slice(pos...max).match(HTML_TAG_OPEN_RE)
|
44
|
-
return false if !match
|
45
|
-
end
|
46
|
-
|
47
|
-
# Make sure tag name is valid
|
48
|
-
return false if HTML_BLOCKS[match[1].downcase] != true
|
49
|
-
return true if silent
|
32
|
+
i = 0
|
33
|
+
while i < HTML_SEQUENCES.length
|
34
|
+
break if HTML_SEQUENCES[i][0].match(lineText)
|
35
|
+
i += 1
|
36
|
+
end
|
37
|
+
|
38
|
+
return false if i == HTML_SEQUENCES.length
|
50
39
|
|
51
|
-
|
52
|
-
|
40
|
+
if silent
|
41
|
+
# true if this sequence can be a terminator, false otherwise
|
42
|
+
return HTML_SEQUENCES[i][2]
|
53
43
|
end
|
54
44
|
|
55
|
-
# If we are here - we detected HTML block.
|
56
|
-
# Let's roll down till empty line (block end).
|
57
45
|
nextLine = startLine + 1
|
58
|
-
|
59
|
-
|
46
|
+
|
47
|
+
# If we are here - we detected HTML block.
|
48
|
+
# Let's roll down till block end.
|
49
|
+
if !HTML_SEQUENCES[i][1].match(lineText)
|
50
|
+
while nextLine < endLine
|
51
|
+
break if state.tShift[nextLine] < state.blkIndent
|
52
|
+
|
53
|
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
54
|
+
max = state.eMarks[nextLine]
|
55
|
+
lineText = state.src.slice(pos...max)
|
56
|
+
|
57
|
+
if HTML_SEQUENCES[i][1].match(lineText)
|
58
|
+
nextLine += 1 if lineText.length != 0
|
59
|
+
break
|
60
|
+
end
|
61
|
+
nextLine += 1
|
62
|
+
end
|
60
63
|
end
|
61
64
|
|
62
65
|
state.line = nextLine
|
63
66
|
|
64
67
|
token = state.push('html_block', '', 0)
|
65
|
-
token.map = [ startLine,
|
66
|
-
token.content = state.getLines(startLine, nextLine,
|
68
|
+
token.map = [ startLine, nextLine ]
|
69
|
+
token.content = state.getLines(startLine, nextLine, state.blkIndent, true)
|
67
70
|
|
68
71
|
return true
|
69
72
|
end
|
@@ -32,8 +32,9 @@ module MarkdownIt
|
|
32
32
|
# or -1 on fail.
|
33
33
|
#------------------------------------------------------------------------------
|
34
34
|
def self.skipOrderedListMarker(state, startLine)
|
35
|
-
|
36
|
-
|
35
|
+
start = state.bMarks[startLine] + state.tShift[startLine]
|
36
|
+
pos = start
|
37
|
+
max = state.eMarks[startLine]
|
37
38
|
|
38
39
|
# List marker should have at least 2 chars (digit + dot)
|
39
40
|
return -1 if (pos + 1 >= max)
|
@@ -52,6 +53,11 @@ module MarkdownIt
|
|
52
53
|
pos += 1
|
53
54
|
|
54
55
|
if (ch >= 0x30 && ch <= 0x39) # >= 0 && <= 9
|
56
|
+
|
57
|
+
# List marker should have no more than 9 digits
|
58
|
+
# (prevents integer overflow in browsers)
|
59
|
+
return -1 if pos - start >= 10
|
60
|
+
|
55
61
|
next
|
56
62
|
end
|
57
63
|
|
@@ -114,7 +120,7 @@ module MarkdownIt
|
|
114
120
|
start = state.bMarks[startLine] + state.tShift[startLine]
|
115
121
|
markerValue = state.src[start, posAfterMarker - start - 1].to_i
|
116
122
|
token = state.push('ordered_list_open', 'ol', 1)
|
117
|
-
if (markerValue
|
123
|
+
if (markerValue != 1)
|
118
124
|
token.attrs = [ [ 'start', markerValue ] ]
|
119
125
|
end
|
120
126
|
|
@@ -138,6 +138,19 @@ module MarkdownIt
|
|
138
138
|
pos += 1
|
139
139
|
end
|
140
140
|
|
141
|
+
if (pos < max && str.charCodeAt(pos) != 0x0A)
|
142
|
+
if (title)
|
143
|
+
# garbage at the end of the line after title,
|
144
|
+
# but it could still be a valid reference if we roll back
|
145
|
+
title = ''
|
146
|
+
pos = destEndPos
|
147
|
+
lines = destEndLineNo
|
148
|
+
while (pos < max && str.charCodeAt(pos) == 0x20) # space
|
149
|
+
pos += 1
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
141
154
|
if (pos < max && str.charCodeAt(pos) != 0x0A)
|
142
155
|
# garbage at the end of the line
|
143
156
|
return false
|
@@ -1,44 +1,44 @@
|
|
1
|
-
require 'kramdown'
|
2
|
-
|
3
|
-
runs = 50
|
4
|
-
files = ['mdsyntax.text', 'mdbasics.text']
|
5
|
-
benchmark_dir = File.join(File.dirname(__FILE__), '../../benchmark')
|
6
|
-
|
7
|
-
puts
|
8
|
-
puts "Running tests on #{Time.now.strftime("%Y-%m-%d")} under #{RUBY_DESCRIPTION}"
|
9
|
-
|
10
|
-
files.each do |file|
|
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
|
-
end
|
39
|
-
|
40
|
-
describe "Benchmark Test" do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
1
|
+
# require 'kramdown'
|
2
|
+
#
|
3
|
+
# runs = 50
|
4
|
+
# files = ['mdsyntax.text', 'mdbasics.text']
|
5
|
+
# benchmark_dir = File.join(File.dirname(__FILE__), '../../benchmark')
|
6
|
+
#
|
7
|
+
# puts
|
8
|
+
# puts "Running tests on #{Time.now.strftime("%Y-%m-%d")} under #{RUBY_DESCRIPTION}"
|
9
|
+
#
|
10
|
+
# files.each do |file|
|
11
|
+
# data = File.read(File.join(benchmark_dir, file))
|
12
|
+
# puts
|
13
|
+
# puts "==> Test using file #{file} and #{runs} runs"
|
14
|
+
#
|
15
|
+
# # results = Benchmark.bmbm do |b|
|
16
|
+
# results = Benchmark.bm do |b|
|
17
|
+
# b.report("motion-markdown-it #{MotionMarkdownIt::VERSION}") do
|
18
|
+
# parser = MarkdownIt::Parser.new({ html: true, linkify: true, typographer: true })
|
19
|
+
# runs.times { parser.render(data) }
|
20
|
+
# end
|
21
|
+
# b.report("kramdown #{Kramdown::VERSION}") { runs.times { Kramdown::Document.new(data).to_html } }
|
22
|
+
# # b.report("markdown-it 4.0.1 JS") { runs.times { NSApplication.sharedApplication.delegate.markdown_it(data) } }
|
23
|
+
# # b.report(" hoedown 3.0.1") do
|
24
|
+
# # runs.times do
|
25
|
+
# # document = HoedownDocument.new
|
26
|
+
# # document.initWithHtmlRendererWithFlags(FLAGS)
|
27
|
+
# # html = document.renderMarkdownString(data)
|
28
|
+
# # end
|
29
|
+
# # end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # puts
|
33
|
+
# # puts "Real time of X divided by real time of kramdown"
|
34
|
+
# # kd = results.shift.real
|
35
|
+
# # %w[hoedown].each do |name|
|
36
|
+
# # puts name.ljust(19) << (results.shift.real/kd).round(4).to_s
|
37
|
+
# # end
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# describe "Benchmark Test" do
|
41
|
+
# it "benchmarks with mdsyntax.text and mdbasics.text" do
|
42
|
+
# expect(true).to eq true
|
43
|
+
# end
|
44
|
+
# end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-markdown-it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Walker
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mdurl-rb
|
@@ -46,9 +46,23 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '1.
|
49
|
+
version: '1.2'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.2'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: bacon-expect
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
52
66
|
version_requirements: !ruby/object:Gem::Requirement
|
53
67
|
requirements:
|
54
68
|
- - "~>"
|