motion-markdown-it 0.4.0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +243 -0
  3. data/lib/motion-markdown-it.rb +71 -0
  4. data/lib/motion-markdown-it/common/entities.rb +1084 -0
  5. data/lib/motion-markdown-it/common/html_blocks.rb +60 -0
  6. data/lib/motion-markdown-it/common/html_re.rb +28 -0
  7. data/lib/motion-markdown-it/common/string.rb +14 -0
  8. data/lib/motion-markdown-it/common/url_schemas.rb +173 -0
  9. data/lib/motion-markdown-it/common/utils.rb +216 -0
  10. data/lib/motion-markdown-it/helpers/parse_link_destination.rb +75 -0
  11. data/lib/motion-markdown-it/helpers/parse_link_label.rb +51 -0
  12. data/lib/motion-markdown-it/helpers/parse_link_title.rb +48 -0
  13. data/lib/motion-markdown-it/index.rb +507 -0
  14. data/lib/motion-markdown-it/parser_block.rb +113 -0
  15. data/lib/motion-markdown-it/parser_core.rb +46 -0
  16. data/lib/motion-markdown-it/parser_inline.rb +121 -0
  17. data/lib/motion-markdown-it/presets/commonmark.rb +76 -0
  18. data/lib/motion-markdown-it/presets/default.rb +42 -0
  19. data/lib/motion-markdown-it/presets/zero.rb +59 -0
  20. data/lib/motion-markdown-it/renderer.rb +286 -0
  21. data/lib/motion-markdown-it/ruler.rb +327 -0
  22. data/lib/motion-markdown-it/rules_block/blockquote.rb +138 -0
  23. data/lib/motion-markdown-it/rules_block/code.rb +35 -0
  24. data/lib/motion-markdown-it/rules_block/fence.rb +94 -0
  25. data/lib/motion-markdown-it/rules_block/heading.rb +56 -0
  26. data/lib/motion-markdown-it/rules_block/hr.rb +45 -0
  27. data/lib/motion-markdown-it/rules_block/html_block.rb +73 -0
  28. data/lib/motion-markdown-it/rules_block/lheading.rb +54 -0
  29. data/lib/motion-markdown-it/rules_block/list.rb +242 -0
  30. data/lib/motion-markdown-it/rules_block/paragraph.rb +51 -0
  31. data/lib/motion-markdown-it/rules_block/reference.rb +161 -0
  32. data/lib/motion-markdown-it/rules_block/state_block.rb +184 -0
  33. data/lib/motion-markdown-it/rules_block/table.rb +161 -0
  34. data/lib/motion-markdown-it/rules_core/block.rb +20 -0
  35. data/lib/motion-markdown-it/rules_core/inline.rb +20 -0
  36. data/lib/motion-markdown-it/rules_core/linkify.rb +138 -0
  37. data/lib/motion-markdown-it/rules_core/normalize.rb +44 -0
  38. data/lib/motion-markdown-it/rules_core/replacements.rb +90 -0
  39. data/lib/motion-markdown-it/rules_core/smartquotes.rb +158 -0
  40. data/lib/motion-markdown-it/rules_core/state_core.rb +20 -0
  41. data/lib/motion-markdown-it/rules_inline/autolink.rb +74 -0
  42. data/lib/motion-markdown-it/rules_inline/backticks.rb +51 -0
  43. data/lib/motion-markdown-it/rules_inline/emphasis.rb +172 -0
  44. data/lib/motion-markdown-it/rules_inline/entity.rb +51 -0
  45. data/lib/motion-markdown-it/rules_inline/escape.rb +55 -0
  46. data/lib/motion-markdown-it/rules_inline/html_inline.rb +49 -0
  47. data/lib/motion-markdown-it/rules_inline/image.rb +158 -0
  48. data/lib/motion-markdown-it/rules_inline/link.rb +153 -0
  49. data/lib/motion-markdown-it/rules_inline/newline.rb +47 -0
  50. data/lib/motion-markdown-it/rules_inline/state_inline.rb +57 -0
  51. data/lib/motion-markdown-it/rules_inline/strikethrough.rb +130 -0
  52. data/lib/motion-markdown-it/rules_inline/text.rb +94 -0
  53. data/lib/motion-markdown-it/token.rb +134 -0
  54. data/lib/motion-markdown-it/version.rb +5 -0
  55. data/spec/motion-markdown-it/bench_mark_spec.rb +44 -0
  56. data/spec/motion-markdown-it/commonmark_spec.rb +16 -0
  57. data/spec/motion-markdown-it/markdown_it_spec.rb +18 -0
  58. data/spec/motion-markdown-it/misc_spec.rb +277 -0
  59. data/spec/motion-markdown-it/ruler_spec.rb +153 -0
  60. data/spec/motion-markdown-it/testgen_helper.rb +68 -0
  61. data/spec/motion-markdown-it/token_spec.rb +17 -0
  62. data/spec/motion-markdown-it/utils_spec.rb +82 -0
  63. data/spec/spec_helper.rb +6 -0
  64. metadata +158 -0
@@ -0,0 +1,68 @@
1
+ # Markdown-It ignores CM where an empty blockquote tag gets rendered with a
2
+ # newline. This changes the output so that the tests pass [2058, 2381, and 2388]
3
+ #------------------------------------------------------------------------------
4
+ def normalize(text)
5
+ return text.gsub(/<blockquote>\n<\/blockquote>/, '<blockquote></blockquote>')
6
+ end
7
+
8
+ #------------------------------------------------------------------------------
9
+ def get_tests(specfile)
10
+ line_number = 0
11
+ start_line = 0
12
+ end_line = 0
13
+ example_number = 0
14
+ markdown_lines = []
15
+ html_lines = []
16
+ state = 0 # 0 regular text, 1 markdown example, 2 html output
17
+ headertext = ''
18
+ tests = []
19
+ header_re = /#+ /
20
+ filename = File.basename(specfile)
21
+
22
+ File.open(specfile) do |specf|
23
+ specf.each_line do |line|
24
+ line_number += 1
25
+ if state == 0 && header_re =~ line
26
+ headertext = line.gsub(header_re, '').strip
27
+ end
28
+ if line.strip == "."
29
+ state = (state + 1) % 3
30
+ if state == 0
31
+ example_number += 1
32
+ end_line = line_number
33
+ tests << {
34
+ markdown: markdown_lines.join.gsub('→',"\t"),
35
+ html: html_lines.join,
36
+ example: example_number,
37
+ start_line: start_line,
38
+ end_line: end_line,
39
+ section: headertext,
40
+ filename: filename}
41
+ start_line = 0
42
+ markdown_lines = []
43
+ html_lines = []
44
+ end
45
+ elsif state == 1
46
+ if start_line == 0
47
+ start_line = line_number - 1
48
+ end
49
+ markdown_lines << line
50
+ elsif state == 2
51
+ html_lines << line
52
+ end
53
+ end
54
+ end
55
+ return tests
56
+ end
57
+
58
+ #------------------------------------------------------------------------------
59
+ def define_test(testcase, parser, debug_tokens = false)
60
+
61
+ it "#{testcase[:filename]} #{testcase[:section]} (#{testcase[:example].to_s}/#{testcase[:start_line]}-#{testcase[:end_line]}) with markdown:\n#{testcase[:markdown]}" do
62
+ if debug_tokens
63
+ parser.parse(testcase[:markdown], { references: {} }).each {|token| pp token.to_json}
64
+ end
65
+ expect(parser.render(testcase[:markdown])).to eq normalize(testcase[:html])
66
+ end
67
+
68
+ end
@@ -0,0 +1,17 @@
1
+ describe "Token" do
2
+
3
+ it 'attr' do
4
+ t = MarkdownIt::Token.new('test_token', 'tok', 1)
5
+
6
+ expect(t.attrs).to eq nil
7
+ expect(t.attrIndex('foo')).to eq -1
8
+
9
+ t.attrPush([ 'foo', 'bar' ])
10
+ t.attrPush([ 'baz', 'bad' ])
11
+
12
+ expect(t.attrIndex('foo')).to eq 0
13
+ expect(t.attrIndex('baz')).to eq 1
14
+ expect(t.attrIndex('none')).to eq -1
15
+ end
16
+
17
+ end
@@ -0,0 +1,82 @@
1
+ include MarkdownIt::Common::Utils
2
+
3
+ describe 'Utils' do
4
+
5
+ #------------------------------------------------------------------------------
6
+ it 'fromCodePoint' do
7
+ expect(fromCodePoint(0x20)).to eq ' '
8
+ expect(fromCodePoint(0x1F601)).to eq '😁'
9
+ end
10
+
11
+ #------------------------------------------------------------------------------
12
+ it 'isValidEntityCode' do
13
+ expect(isValidEntityCode(0x20)).to eq true
14
+ expect(isValidEntityCode(0xD800)).to eq false
15
+ expect(isValidEntityCode(0xFDD0)).to eq false
16
+ expect(isValidEntityCode(0x1FFFF)).to eq false
17
+ expect(isValidEntityCode(0x1FFFE)).to eq false
18
+ expect(isValidEntityCode(0x00)).to eq false
19
+ expect(isValidEntityCode(0x0B)).to eq false
20
+ expect(isValidEntityCode(0x0E)).to eq false
21
+ expect(isValidEntityCode(0x7F)).to eq false
22
+ end
23
+
24
+ # /*it('replaceEntities', function () {
25
+ # var replaceEntities = require('../lib/common/utils').replaceEntities;
26
+ #
27
+ # assert.strictEqual(replaceEntities('&amp;'), '&');
28
+ # assert.strictEqual(replaceEntities('&#32;'), ' ');
29
+ # assert.strictEqual(replaceEntities('&#x20;'), ' ');
30
+ # assert.strictEqual(replaceEntities('&amp;&amp;'), '&&');
31
+ #
32
+ # assert.strictEqual(replaceEntities('&am;'), '&am;');
33
+ # assert.strictEqual(replaceEntities('&#00;'), '&#00;');
34
+ # });*/
35
+
36
+ #------------------------------------------------------------------------------
37
+ it 'assign' do
38
+ expect(assign({ a: 1 }, nil, { b: 2 })).to eq ({ a: 1, b: 2 })
39
+ expect {
40
+ assign({}, 123)
41
+ }.to raise_error
42
+ end
43
+
44
+ #------------------------------------------------------------------------------
45
+ it 'escapeRE' do
46
+ expect(escapeRE(' .?*+^$[]\\(){}|-')).to eq ' \\.\\?\\*\\+\\^\\$\\[\\]\\\\\\(\\)\\{\\}\\|\\-'
47
+ end
48
+
49
+ #------------------------------------------------------------------------------
50
+ it 'isWhiteSpace' do
51
+ expect(isWhiteSpace(0x2000)).to eq true
52
+ expect(isWhiteSpace(0x09)).to eq true
53
+
54
+ expect(isWhiteSpace(0x30)).to eq false
55
+ end
56
+
57
+ #------------------------------------------------------------------------------
58
+ it 'isMdAsciiPunct' do
59
+ expect(isMdAsciiPunct(0x30)).to eq false
60
+
61
+ '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('').each do |ch|
62
+ expect(isMdAsciiPunct(ch.ord)).to eq true
63
+ end
64
+ end
65
+
66
+ #------------------------------------------------------------------------------
67
+ it 'unescapeMd' do
68
+ expect(unescapeMd('\\foo')).to eq '\\foo'
69
+ expect(unescapeMd('foo')).to eq 'foo'
70
+
71
+ '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('').each do |ch|
72
+ expect(unescapeMd('\\' + ch)).to eq ch
73
+ end
74
+ end
75
+
76
+ #------------------------------------------------------------------------------
77
+ it "escapeHtml" do
78
+ str = '<hr>x & "y"'
79
+ expect(escapeHtml(str)).to eq '&lt;hr&gt;x &amp; &quot;y&quot;'
80
+ end
81
+
82
+ end
@@ -0,0 +1,6 @@
1
+ # make sure to have `--require spec_helper` in `.rspec` to have the
2
+ # spec_helper.rb included automatically in spec files
3
+ require 'byebug'
4
+ require 'benchmark'
5
+ require 'motion-markdown-it/testgen_helper'
6
+ require 'motion-markdown-it'
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-markdown-it
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Brett Walker
8
+ - Vitaly Puzrin
9
+ - Alex Kocharin
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-03-27 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mdurl-rb
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: uc.micro-rb
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: linkify-it-rb
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.1'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.1'
57
+ description: Ruby/RubyMotion version of markdown-it
58
+ email: github@digitalmoksha.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - README.md
64
+ - lib/motion-markdown-it.rb
65
+ - lib/motion-markdown-it/common/entities.rb
66
+ - lib/motion-markdown-it/common/html_blocks.rb
67
+ - lib/motion-markdown-it/common/html_re.rb
68
+ - lib/motion-markdown-it/common/string.rb
69
+ - lib/motion-markdown-it/common/url_schemas.rb
70
+ - lib/motion-markdown-it/common/utils.rb
71
+ - lib/motion-markdown-it/helpers/parse_link_destination.rb
72
+ - lib/motion-markdown-it/helpers/parse_link_label.rb
73
+ - lib/motion-markdown-it/helpers/parse_link_title.rb
74
+ - lib/motion-markdown-it/index.rb
75
+ - lib/motion-markdown-it/parser_block.rb
76
+ - lib/motion-markdown-it/parser_core.rb
77
+ - lib/motion-markdown-it/parser_inline.rb
78
+ - lib/motion-markdown-it/presets/commonmark.rb
79
+ - lib/motion-markdown-it/presets/default.rb
80
+ - lib/motion-markdown-it/presets/zero.rb
81
+ - lib/motion-markdown-it/renderer.rb
82
+ - lib/motion-markdown-it/ruler.rb
83
+ - lib/motion-markdown-it/rules_block/blockquote.rb
84
+ - lib/motion-markdown-it/rules_block/code.rb
85
+ - lib/motion-markdown-it/rules_block/fence.rb
86
+ - lib/motion-markdown-it/rules_block/heading.rb
87
+ - lib/motion-markdown-it/rules_block/hr.rb
88
+ - lib/motion-markdown-it/rules_block/html_block.rb
89
+ - lib/motion-markdown-it/rules_block/lheading.rb
90
+ - lib/motion-markdown-it/rules_block/list.rb
91
+ - lib/motion-markdown-it/rules_block/paragraph.rb
92
+ - lib/motion-markdown-it/rules_block/reference.rb
93
+ - lib/motion-markdown-it/rules_block/state_block.rb
94
+ - lib/motion-markdown-it/rules_block/table.rb
95
+ - lib/motion-markdown-it/rules_core/block.rb
96
+ - lib/motion-markdown-it/rules_core/inline.rb
97
+ - lib/motion-markdown-it/rules_core/linkify.rb
98
+ - lib/motion-markdown-it/rules_core/normalize.rb
99
+ - lib/motion-markdown-it/rules_core/replacements.rb
100
+ - lib/motion-markdown-it/rules_core/smartquotes.rb
101
+ - lib/motion-markdown-it/rules_core/state_core.rb
102
+ - lib/motion-markdown-it/rules_inline/autolink.rb
103
+ - lib/motion-markdown-it/rules_inline/backticks.rb
104
+ - lib/motion-markdown-it/rules_inline/emphasis.rb
105
+ - lib/motion-markdown-it/rules_inline/entity.rb
106
+ - lib/motion-markdown-it/rules_inline/escape.rb
107
+ - lib/motion-markdown-it/rules_inline/html_inline.rb
108
+ - lib/motion-markdown-it/rules_inline/image.rb
109
+ - lib/motion-markdown-it/rules_inline/link.rb
110
+ - lib/motion-markdown-it/rules_inline/newline.rb
111
+ - lib/motion-markdown-it/rules_inline/state_inline.rb
112
+ - lib/motion-markdown-it/rules_inline/strikethrough.rb
113
+ - lib/motion-markdown-it/rules_inline/text.rb
114
+ - lib/motion-markdown-it/token.rb
115
+ - lib/motion-markdown-it/version.rb
116
+ - spec/motion-markdown-it/bench_mark_spec.rb
117
+ - spec/motion-markdown-it/commonmark_spec.rb
118
+ - spec/motion-markdown-it/markdown_it_spec.rb
119
+ - spec/motion-markdown-it/misc_spec.rb
120
+ - spec/motion-markdown-it/ruler_spec.rb
121
+ - spec/motion-markdown-it/testgen_helper.rb
122
+ - spec/motion-markdown-it/token_spec.rb
123
+ - spec/motion-markdown-it/utils_spec.rb
124
+ - spec/spec_helper.rb
125
+ homepage: https://github.com/digitalmoksha/motion-markdown-it
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.4.5
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Ruby version markdown-it
149
+ test_files:
150
+ - spec/motion-markdown-it/bench_mark_spec.rb
151
+ - spec/motion-markdown-it/commonmark_spec.rb
152
+ - spec/motion-markdown-it/markdown_it_spec.rb
153
+ - spec/motion-markdown-it/misc_spec.rb
154
+ - spec/motion-markdown-it/ruler_spec.rb
155
+ - spec/motion-markdown-it/testgen_helper.rb
156
+ - spec/motion-markdown-it/token_spec.rb
157
+ - spec/motion-markdown-it/utils_spec.rb
158
+ - spec/spec_helper.rb