motion-markdown-it 4.4.0 → 8.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +69 -16
  3. data/lib/motion-markdown-it.rb +7 -5
  4. data/lib/motion-markdown-it/common/html_blocks.rb +6 -2
  5. data/lib/motion-markdown-it/common/utils.rb +19 -4
  6. data/lib/motion-markdown-it/helpers/helper_wrapper.rb +9 -0
  7. data/lib/motion-markdown-it/helpers/parse_link_destination.rb +8 -7
  8. data/lib/motion-markdown-it/index.rb +60 -18
  9. data/lib/motion-markdown-it/parser_block.rb +7 -10
  10. data/lib/motion-markdown-it/parser_inline.rb +50 -14
  11. data/lib/motion-markdown-it/presets/commonmark.rb +7 -1
  12. data/lib/motion-markdown-it/presets/default.rb +4 -3
  13. data/lib/motion-markdown-it/presets/zero.rb +6 -1
  14. data/lib/motion-markdown-it/renderer.rb +46 -14
  15. data/lib/motion-markdown-it/rules_block/blockquote.rb +167 -31
  16. data/lib/motion-markdown-it/rules_block/code.rb +4 -3
  17. data/lib/motion-markdown-it/rules_block/fence.rb +9 -4
  18. data/lib/motion-markdown-it/rules_block/heading.rb +8 -3
  19. data/lib/motion-markdown-it/rules_block/hr.rb +10 -5
  20. data/lib/motion-markdown-it/rules_block/html_block.rb +6 -3
  21. data/lib/motion-markdown-it/rules_block/lheading.rb +64 -26
  22. data/lib/motion-markdown-it/rules_block/list.rb +91 -22
  23. data/lib/motion-markdown-it/rules_block/paragraph.rb +14 -9
  24. data/lib/motion-markdown-it/rules_block/reference.rb +24 -14
  25. data/lib/motion-markdown-it/rules_block/state_block.rb +79 -24
  26. data/lib/motion-markdown-it/rules_block/table.rb +52 -26
  27. data/lib/motion-markdown-it/rules_core/normalize.rb +1 -23
  28. data/lib/motion-markdown-it/rules_core/replacements.rb +22 -2
  29. data/lib/motion-markdown-it/rules_core/smartquotes.rb +41 -12
  30. data/lib/motion-markdown-it/rules_inline/autolink.rb +5 -4
  31. data/lib/motion-markdown-it/rules_inline/balance_pairs.rb +48 -0
  32. data/lib/motion-markdown-it/rules_inline/emphasis.rb +104 -149
  33. data/lib/motion-markdown-it/rules_inline/entity.rb +2 -2
  34. data/lib/motion-markdown-it/rules_inline/escape.rb +5 -3
  35. data/lib/motion-markdown-it/rules_inline/image.rb +12 -23
  36. data/lib/motion-markdown-it/rules_inline/link.rb +20 -25
  37. data/lib/motion-markdown-it/rules_inline/newline.rb +2 -1
  38. data/lib/motion-markdown-it/rules_inline/state_inline.rb +60 -1
  39. data/lib/motion-markdown-it/rules_inline/strikethrough.rb +81 -97
  40. data/lib/motion-markdown-it/rules_inline/text_collapse.rb +40 -0
  41. data/lib/motion-markdown-it/token.rb +46 -1
  42. data/lib/motion-markdown-it/version.rb +1 -1
  43. data/spec/motion-markdown-it/markdown_it_spec.rb +2 -2
  44. data/spec/motion-markdown-it/misc_spec.rb +90 -14
  45. data/spec/motion-markdown-it/testgen_helper.rb +1 -1
  46. data/spec/spec_helper.rb +2 -3
  47. metadata +13 -13
  48. data/lib/motion-markdown-it/common/url_schemas.rb +0 -173
  49. data/spec/motion-markdown-it/bench_mark_spec.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb7bc35a96283f575397326f35cc15789b4700fe
4
- data.tar.gz: feacd41709859ddb7b8fd30f288af2a53c80c562
3
+ metadata.gz: e01060bf95d44944bd2081ba624c238497dfc66b
4
+ data.tar.gz: 8fdb0bc2d0b0d45dd2912af9541a34dba71776a2
5
5
  SHA512:
6
- metadata.gz: d64baed7b2ed7ecadc4b3a31b9d723502ab564e08871401b0d9b2d7dfeb017e12c09656692639f6d1b5dc911a0cc4605c8d832181e2c5b05c43d0e725c6edec0
7
- data.tar.gz: 6dc2d585c57113b580d398c9370db04a22c7cb8c8470af53857c8a1b5df67601368c4aa557cf4b791201a3cef7e1a7d063190857d059f24508a546d6b77ac874
6
+ metadata.gz: e8e57f8c16c37aa08854257b56caf0a40428d8bce50c5b2ce7ad1d59ff724029fc97c59b152bd63e196b200da7ad7ef2a56132622c6e54279830b233e1baf398
7
+ data.tar.gz: 0adebed4df5b22d1f51c1204bea082074631d190705cc53056ddb7a0e2079aa8d3900fa71d8dd876852c113e45d07b3fcffb1b7325c35fe4a2690ca63f9d5bfc
data/README.md CHANGED
@@ -3,17 +3,17 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/motion-markdown-it.svg)](http://badge.fury.io/rb/motion-markdown-it)
4
4
  [![Build Status](https://travis-ci.org/digitalmoksha/motion-markdown-it.svg?branch=master)](https://travis-ci.org/digitalmoksha/motion-markdown-it)
5
5
 
6
- https://travis-ci.org/digitalmoksha/motion-markdown-it.svg?branch=master
7
6
  Ruby/RubyMotion version of Markdown-it (CommonMark compliant and extendable)
8
7
 
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
+ 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
9
+
10
+ ---
10
11
 
11
12
  __[Javascript Live demo](https://markdown-it.github.io)__
12
13
 
13
14
  Follows the __[CommonMark spec](http://spec.commonmark.org/)__ + adds syntax extensions & sugar (URL autolinking, typographer).
14
15
  - Configurable syntax. You can add new rules and even replace existing ones.
15
16
  - [Safe](https://github.com/markdown-it/markdown-it/tree/master/docs/security.md) by default.
16
- - Community-written plugins
17
17
  - Community-written plugins
18
18
  * [Ruby/RubyMotion](https://github.com/digitalmoksha/motion-markdown-it-plugins)
19
19
  * [original javascript plugins](https://www.npmjs.org/browse/keyword/markdown-it-plugin) and [other packages](https://www.npmjs.org/browse/keyword/markdown-it) on npm.
@@ -24,7 +24,31 @@ The benefit of this project, for me at least, is to have a standardized CommonMa
24
24
 
25
25
  ## Performance
26
26
 
27
- Performance is still an issue. While it performs reasonably well with small to medium files, it degrades for large files. Work in progress...
27
+ Performance is slower than, say, `kramdown`, but for most uses, is pretty fast. Here are some non-scientific benchmarks. Note that `kramdown` and `redcarpet` are not CommonMark compliant.
28
+
29
+ ```
30
+ Running tests on 2018-04-04 under ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
31
+
32
+ ==> Test using file mdsyntax.text and 500 runs
33
+ Rehearsal -------------------------------------------------------------
34
+ motion-markdown-it 8.4.1 17.940000 0.710000 18.650000 ( 18.721629)
35
+ kramdown 1.16.2 14.720000 0.180000 14.900000 ( 15.015840)
36
+ commonmarker 0.17.9 0.220000 0.000000 0.220000 ( 0.222098)
37
+ redcarpet 3.4.0 0.140000 0.010000 0.150000 ( 0.145821)
38
+ --------------------------------------------------- total: 33.920000sec
39
+
40
+ user system total real
41
+ motion-markdown-it 8.4.1 18.290000 0.720000 19.010000 ( 19.113943)
42
+ kramdown 1.16.2 13.320000 0.110000 13.430000 ( 13.459096)
43
+ commonmarker 0.17.9 0.190000 0.000000 0.190000 ( 0.187104)
44
+ redcarpet 3.4.0 0.120000 0.000000 0.120000 ( 0.123931)
45
+
46
+ Real time as a factor of motion-markdown-it
47
+ motion-markdown-it 8.4.1 1.0
48
+ kramdown 1.16.2 0.7042
49
+ commonmarker 0.17.9 0.0098
50
+ redcarpet 3.4.0 0.0065
51
+ ````
28
52
 
29
53
  ## Table of content
30
54
 
@@ -114,7 +138,7 @@ parser = MarkdownIt::Parser.new({
114
138
  quotes: '“”‘’',
115
139
 
116
140
  # Highlighter function. Should return escaped HTML,
117
- # or nil if the source string is not changed and should be escaped externaly.
141
+ # or nil if the source string is not changed and should be escaped externally.
118
142
  highlight: lambda {|str, lang| return nil}
119
143
  })
120
144
  ```
@@ -148,7 +172,7 @@ var md = require('markdown-it')()
148
172
  Apply syntax highlighting to fenced code blocks with the `highlight` option:
149
173
 
150
174
  ```js
151
- var hljs = require('highlight.js') // https://highlightjs.org/
175
+ var hljs = require('highlight.js'); // https://highlightjs.org/
152
176
 
153
177
  // Actual default values
154
178
  var md = require('markdown-it')({
@@ -159,15 +183,41 @@ var md = require('markdown-it')({
159
183
  } catch (__) {}
160
184
  }
161
185
 
162
- try {
163
- return hljs.highlightAuto(str).value;
164
- } catch (__) {}
165
-
166
186
  return ''; // use external default escaping
167
187
  }
168
188
  });
169
189
  ```
170
190
 
191
+ Or with full wrapper override (if you need assign class to `<pre>`):
192
+
193
+ ```js
194
+ var hljs = require('highlight.js'); // https://highlightjs.org/
195
+
196
+ // Actual default values
197
+ var md = require('markdown-it')({
198
+ highlight: function (str, lang) {
199
+ if (lang && hljs.getLanguage(lang)) {
200
+ try {
201
+ return '<pre class="hljs"><code>' +
202
+ hljs.highlight(lang, str, true).value +
203
+ '</code></pre>';
204
+ } catch (__) {}
205
+ }
206
+
207
+ return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
208
+ }
209
+ });
210
+ ```
211
+
212
+ ### Linkify
213
+
214
+ `linkify: true` uses [linkify-it](https://github.com/markdown-it/linkify-it). To
215
+ configure linkify-it, access the linkify instance through `md.linkify`:
216
+
217
+ ```js
218
+ md.linkify.tlds('.py', false); // disables .py as top level domain
219
+ ```
220
+
171
221
 
172
222
  ## API
173
223
 
@@ -181,8 +231,8 @@ If you are going to write plugins - take a look at
181
231
 
182
232
  Embedded (enabled by default):
183
233
 
184
- - [Tables](https://help.github.com/articles/github-flavored-markdown/#tables) (GFM)
185
- - [Strikethrough](https://help.github.com/articles/github-flavored-markdown/#strikethrough) (GFM)
234
+ - [Tables](https://help.github.com/articles/organizing-information-with-tables/) (GFM)
235
+ - [Strikethrough](https://help.github.com/articles/basic-writing-and-formatting-syntax/#styling-text) (GFM)
186
236
 
187
237
  Via plugins:
188
238
 
@@ -211,7 +261,7 @@ var md = require('markdown-it')()
211
261
  .enable('image');
212
262
 
213
263
  // Enable everything
214
- md = require('markdown-it')('full', {
264
+ md = require('markdown-it')({
215
265
  html: true,
216
266
  linkify: true,
217
267
  typographer: true,
@@ -219,12 +269,14 @@ md = require('markdown-it')('full', {
219
269
  ```
220
270
 
221
271
 
222
- ## Benchmark (for Javascript version)
272
+ ## Benchmark
223
273
 
224
274
  Here is the result of readme parse at MB Pro Retina 2013 (2.4 GHz):
225
275
 
226
276
  ```bash
227
- $ benchmark/benchmark.js readme
277
+ make benchmark-deps
278
+ benchmark/benchmark.js readme
279
+
228
280
  Selected samples: (1 of 28)
229
281
  > README
230
282
 
@@ -232,7 +284,7 @@ Sample: README.md (7774 bytes)
232
284
  > commonmark-reference x 1,222 ops/sec ±0.96% (97 runs sampled)
233
285
  > current x 743 ops/sec ±0.84% (97 runs sampled)
234
286
  > current-commonmark x 1,568 ops/sec ±0.84% (98 runs sampled)
235
- > marked-0.3.2 x 1,587 ops/sec ±4.31% (93 runs sampled)
287
+ > marked x 1,587 ops/sec ±4.31% (93 runs sampled)
236
288
  ```
237
289
 
238
290
  __Note.__ CommonMark version runs with [simplified link normalizers](https://github.com/markdown-it/markdown-it/blob/master/benchmark/implementations/current-commonmark/index.js)
@@ -242,6 +294,7 @@ As you can see, `markdown-it` doesn't pay with speed for it's flexibility.
242
294
  Slowdown of "full" version caused by additional features not available in
243
295
  other implementations.
244
296
 
297
+
245
298
  -->
246
299
 
247
300
  ## References / Thanks
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  if defined?(Motion::Project::Config)
4
-
4
+
5
5
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
6
6
  Motion::Project::App.setup do |app|
7
7
  app.files.unshift(Dir.glob(File.join(lib_dir_path, "motion-markdown-it/**/*.rb")))
@@ -12,7 +12,7 @@ if defined?(Motion::Project::Config)
12
12
  require 'uc.micro-rb'
13
13
 
14
14
  else
15
-
15
+
16
16
  require 'mdurl-rb'
17
17
  require 'uc.micro-rb'
18
18
  require 'linkify-it-rb'
@@ -23,13 +23,13 @@ else
23
23
  require 'motion-markdown-it/common/entities'
24
24
  require 'motion-markdown-it/common/utils'
25
25
  require 'motion-markdown-it/common/html_blocks'
26
- require 'motion-markdown-it/common/url_schemas'
27
26
  require 'motion-markdown-it/common/html_re'
28
27
  require 'motion-markdown-it/common/string'
29
28
  require 'motion-markdown-it/common/simpleidn'
30
29
  require 'motion-markdown-it/helpers/parse_link_destination'
31
30
  require 'motion-markdown-it/helpers/parse_link_label'
32
31
  require 'motion-markdown-it/helpers/parse_link_title'
32
+ require 'motion-markdown-it/helpers/helper_wrapper'
33
33
  require 'motion-markdown-it/parser_inline'
34
34
  require 'motion-markdown-it/parser_block'
35
35
  require 'motion-markdown-it/parser_core'
@@ -55,6 +55,7 @@ else
55
55
  require 'motion-markdown-it/rules_block/table'
56
56
  require 'motion-markdown-it/rules_inline/autolink'
57
57
  require 'motion-markdown-it/rules_inline/backticks'
58
+ require 'motion-markdown-it/rules_inline/balance_pairs'
58
59
  require 'motion-markdown-it/rules_inline/emphasis'
59
60
  require 'motion-markdown-it/rules_inline/entity'
60
61
  require 'motion-markdown-it/rules_inline/escape'
@@ -64,10 +65,11 @@ else
64
65
  require 'motion-markdown-it/rules_inline/newline'
65
66
  require 'motion-markdown-it/rules_inline/state_inline'
66
67
  require 'motion-markdown-it/rules_inline/strikethrough'
68
+ require 'motion-markdown-it/rules_inline/text_collapse'
67
69
  require 'motion-markdown-it/rules_inline/text'
68
-
70
+
69
71
  require 'motion-markdown-it/ruler'
70
72
  require 'motion-markdown-it/token'
71
73
  require 'motion-markdown-it/index'
72
-
74
+
73
75
  end
@@ -29,10 +29,16 @@ module MarkdownIt
29
29
  'frame',
30
30
  'frameset',
31
31
  'h1',
32
+ 'h2',
33
+ 'h3',
34
+ 'h4',
35
+ 'h5',
36
+ 'h6',
32
37
  'head',
33
38
  'header',
34
39
  'hr',
35
40
  'html',
41
+ 'iframe',
36
42
  'legend',
37
43
  'li',
38
44
  'link',
@@ -47,10 +53,8 @@ module MarkdownIt
47
53
  'option',
48
54
  'p',
49
55
  'param',
50
- 'pre',
51
56
  'section',
52
57
  'source',
53
- 'title',
54
58
  'summary',
55
59
  'table',
56
60
  'tbody',
@@ -51,6 +51,11 @@ module MarkdownIt
51
51
  c.chr(Encoding::UTF_8)
52
52
  end
53
53
 
54
+ #------------------------------------------------------------------------------
55
+ def fromCharCode(c)
56
+ c.chr
57
+ end
58
+
54
59
 
55
60
  UNESCAPE_MD_RE = /\\([\!\"\#\$\%\&\'\(\)\*\+\,\-.\/:;<=>?@\[\\\]^_`{|}~])/
56
61
 
@@ -63,7 +68,7 @@ module MarkdownIt
63
68
  def replaceEntityPattern(match, name)
64
69
  code = 0
65
70
 
66
- return HTMLEntities::MAPPINGS[name].chr(Encoding::UTF_8) if HTMLEntities::MAPPINGS[name]
71
+ return fromCodePoint(HTMLEntities::MAPPINGS[name]) if HTMLEntities::MAPPINGS[name]
67
72
 
68
73
  if (name.charCodeAt(0) == 0x23 && DIGITAL_ENTITY_TEST_RE =~ name) # '#'
69
74
  code = name[1].downcase == 'x' ? name.slice_to_end(2).to_i(16) : name.slice_to_end(1).to_i
@@ -116,6 +121,16 @@ module MarkdownIt
116
121
  str.gsub(REGEXP_ESCAPE_RE) {|s| '\\' + s}
117
122
  end
118
123
 
124
+ #------------------------------------------------------------------------------
125
+ def isSpace(code)
126
+ case code
127
+ when 0x09,
128
+ 0x20
129
+ return true
130
+ end
131
+
132
+ return false
133
+ end
119
134
 
120
135
  # Zs (unicode class) || [\t\f\v\r\n]
121
136
  #------------------------------------------------------------------------------
@@ -142,13 +157,13 @@ module MarkdownIt
142
157
 
143
158
  # Currently without astral characters support.
144
159
  #------------------------------------------------------------------------------
145
- def isPunctChar(char)
146
- return UNICODE_PUNCT_RE =~ char
160
+ def isPunctChar(ch)
161
+ return UNICODE_PUNCT_RE =~ ch
147
162
  end
148
163
 
149
164
 
150
165
  # Markdown ASCII punctuation characters.
151
- #
166
+ #
152
167
  # !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~
153
168
  # http://spec.commonmark.org/0.15/#ascii-punctuation-character
154
169
  #
@@ -0,0 +1,9 @@
1
+ module MarkdownIt
2
+ module Helpers
3
+ class HelperWrapper
4
+ include ParseLinkDestination
5
+ include ParseLinkLabel
6
+ include ParseLinkTitle
7
+ end
8
+ end
9
+ end
@@ -3,18 +3,19 @@
3
3
  module MarkdownIt
4
4
  module Helpers
5
5
  module ParseLinkDestination
6
-
6
+ include Common::Utils
7
+
7
8
  #------------------------------------------------------------------------------
8
9
  def parseLinkDestination(str, pos, max)
9
10
  lines = 0
10
11
  start = pos
11
12
  result = {ok: false, pos: 0, lines: 0, str: ''}
12
13
 
13
- if (str.charCodeAt(pos) == 0x3C ) # <
14
+ if (str.charCodeAt(pos) == 0x3C ) # <
14
15
  pos += 1
15
16
  while (pos < max)
16
17
  code = str.charCodeAt(pos)
17
- return result if (code == 0x0A ) # \n
18
+ return result if (code == 0x0A || isSpace(code)) # \n
18
19
  if (code == 0x3E) # >
19
20
  result[:pos] = pos + 1
20
21
  result[:str] = unescapeAll(str.slice((start + 1)...pos))
@@ -36,7 +37,7 @@ module MarkdownIt
36
37
  # this should be ... } else { ... branch
37
38
 
38
39
  level = 0
39
- while (pos < max)
40
+ while (pos < max)
40
41
  code = str.charCodeAt(pos)
41
42
 
42
43
  break if (code == 0x20)
@@ -51,18 +52,18 @@ module MarkdownIt
51
52
 
52
53
  if (code == 0x28) # (
53
54
  level += 1
54
- break if (level > 1)
55
55
  end
56
56
 
57
57
  if (code == 0x29) # )
58
+ break if (level == 0)
58
59
  level -= 1
59
- break if (level < 0)
60
60
  end
61
61
 
62
62
  pos += 1
63
63
  end
64
64
 
65
- return result if (start == pos)
65
+ return result if start == pos
66
+ return result if level != 0
66
67
 
67
68
  result[:str] = unescapeAll(str.slice(start...pos))
68
69
  result[:lines] = lines
@@ -46,7 +46,7 @@ NORMALIZE_LINK = lambda do |url|
46
46
  end
47
47
  end
48
48
  end
49
-
49
+
50
50
  return MDUrl::Encode.encode(MDUrl::Format.format(parsed))
51
51
  end
52
52
 
@@ -75,29 +75,29 @@ end
75
75
 
76
76
  #------------------------------------------------------------------------------
77
77
  # class MarkdownIt
78
- #
78
+ #
79
79
  # Main parser/renderer class.
80
- #
80
+ #
81
81
  # ##### Usage
82
- #
82
+ #
83
83
  # ```javascript
84
84
  # // node.js, "classic" way:
85
85
  # var MarkdownIt = require('markdown-it'),
86
86
  # md = new MarkdownIt();
87
87
  # var result = md.render('# markdown-it rulezz!');
88
- #
88
+ #
89
89
  # // node.js, the same, but with sugar:
90
90
  # var md = require('markdown-it')();
91
91
  # var result = md.render('# markdown-it rulezz!');
92
- #
92
+ #
93
93
  # // browser without AMD, added to "window" on script load
94
94
  # // Note, there are no dash.
95
95
  # var md = window.markdownit();
96
96
  # var result = md.render('# markdown-it rulezz!');
97
97
  # ```
98
- #
98
+ #
99
99
  # Single line rendering, without paragraph wrap:
100
- #
100
+ #
101
101
  # ```javascript
102
102
  # var md = require('markdown-it')();
103
103
  # var result = md.renderInline('__markdown-it__ rulezz!');
@@ -106,6 +106,7 @@ end
106
106
  module MarkdownIt
107
107
  class Parser
108
108
  include MarkdownIt::Common::Utils
109
+ include MarkdownIt::Helpers
109
110
 
110
111
  attr_accessor :inline
111
112
  attr_accessor :block
@@ -116,7 +117,8 @@ module MarkdownIt
116
117
  attr_accessor :normalizeLink
117
118
  attr_accessor :normalizeLinkText
118
119
  attr_accessor :linkify
119
-
120
+ attr_accessor :helpers
121
+
120
122
  # new MarkdownIt([presetName, options])
121
123
  # - presetName (String): optional, `commonmark` / `zero`
122
124
  # - options (Object)
@@ -158,7 +160,8 @@ module MarkdownIt
158
160
  # `['«\xA0', '\xA0»', '‹\xA0', '\xA0›']` for French (including nbsp).
159
161
  # - __highlight__ - `nil`. Highlighter function for fenced code blocks.
160
162
  # Highlighter `function (str, lang)` should return escaped HTML. It can also
161
- # return nil if the source was not changed and should be escaped externaly.
163
+ # return nil if the source was not changed and should be escaped
164
+ # externaly. If result starts with <pre... internal wrapper is skipped.
162
165
  #
163
166
  # ##### Example
164
167
  #
@@ -186,18 +189,35 @@ module MarkdownIt
186
189
  # highlight: function (str, lang) {
187
190
  # if (lang && hljs.getLanguage(lang)) {
188
191
  # try {
189
- # return hljs.highlight(lang, str).value;
192
+ # return hljs.highlight(lang, str, true).value;
190
193
  # } catch (__) {}
191
194
  # }
192
195
  #
193
- # try {
194
- # return hljs.highlightAuto(str).value;
195
- # } catch (__) {}
196
- #
197
196
  # return ''; // use external default escaping
198
197
  # }
199
198
  # });
200
199
  # ```
200
+ #
201
+ # Or with full wrapper override (if you need assign class to `<pre>`):
202
+ #
203
+ # ```javascript
204
+ # var hljs = require('highlight.js') // https://highlightjs.org/
205
+ #
206
+ # // Actual default values
207
+ # var md = require('markdown-it')({
208
+ # highlight: function (str, lang) {
209
+ # if (lang && hljs.getLanguage(lang)) {
210
+ # try {
211
+ # return '<pre class="hljs"><code>' +
212
+ # hljs.highlight(lang, str, true).value +
213
+ # '</code></pre>';
214
+ # } catch (__) {}
215
+ # }
216
+ #
217
+ # return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
218
+ # }
219
+ # });
220
+ # ```
201
221
  #-----------------------------------------------------------------------------
202
222
  def initialize(presetName = :default, options = {})
203
223
  if options.empty?
@@ -284,6 +304,19 @@ module MarkdownIt
284
304
 
285
305
  # Expose utils & helpers for easy acces from plugins
286
306
 
307
+ # MarkdownIt#utils -> utils
308
+ #
309
+ # Assorted utility functions, useful to write plugins. See details
310
+ # [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.js).
311
+ # this.utils = utils;
312
+
313
+ # MarkdownIt#helpers -> helpers
314
+ #
315
+ # Link components parser functions, useful to write plugins. See details
316
+ # [here](https://github.com/markdown-it/markdown-it/blob/master/lib/helpers).
317
+ # @helpers = assign({}, helpers);
318
+ @helpers = MarkdownIt::Helpers::HelperWrapper.new
319
+
287
320
  @options = {}
288
321
  configure(presetName)
289
322
  set(options) if options
@@ -340,6 +373,9 @@ module MarkdownIt
340
373
  if presets[:components][name][:rules]
341
374
  self.send(name).ruler.enableOnly(presets[:components][name][:rules])
342
375
  end
376
+ if presets[:components][name][:rules2]
377
+ self.send(name).ruler2.enableOnly(presets[:components][name][:rules2])
378
+ end
343
379
  end
344
380
  end
345
381
  return self
@@ -371,8 +407,10 @@ module MarkdownIt
371
407
  result << @core.ruler.enable(list, true)
372
408
  result << @block.ruler.enable(list, true)
373
409
  result << @inline.ruler.enable(list, true)
410
+ result << @inline.ruler2.enable(list, true)
374
411
  result.flatten!
375
-
412
+
413
+
376
414
  missed = list.select {|name| !result.include?(name) }
377
415
  if !(missed.empty? || ignoreInvalid)
378
416
  raise StandardError, "MarkdownIt. Failed to enable unknown rule(s): #{missed}"
@@ -397,6 +435,7 @@ module MarkdownIt
397
435
  result << @core.ruler.disable(list, true)
398
436
  result << @block.ruler.disable(list, true)
399
437
  result << @inline.ruler.disable(list, true)
438
+ result << @inline.ruler2.disable(list, true)
400
439
  result.flatten!
401
440
 
402
441
  missed = list.select {|name| !result.include?(name) }
@@ -418,11 +457,12 @@ module MarkdownIt
418
457
  #
419
458
  # ```ruby
420
459
  # md = MarkdownIt::Parser.new
421
- # md.use(MDPlugin::Iterator, 'foo_replace', 'text',
460
+ # md.use(MDPlugin::Iterator, 'foo_replace', 'text',
422
461
  # lambda {|tokens, idx|
423
462
  # tokens[idx].content = tokens[idx].content.gsub(/foo/, 'bar')
424
463
  # })
425
464
  # ```
465
+ #------------------------------------------------------------------------------
426
466
  def use(plugin, *args)
427
467
  plugin.init_plugin(self, *args)
428
468
  return self
@@ -440,11 +480,13 @@ module MarkdownIt
440
480
  # AST).
441
481
  #
442
482
  # `env` is used to pass data between "distributed" rules and return additional
443
- # metadata like reference info, needed for for renderer. It also can be used to
483
+ # metadata like reference info, needed for the renderer. It also can be used to
444
484
  # inject data in specific cases. Usually, you will be ok to pass `{}`,
445
485
  # and then pass updated object to renderer.
446
486
  #------------------------------------------------------------------------------
447
487
  def parse(src, env)
488
+ raise ArgumentError.new('Input data should be a String') if !src.is_a?(String)
489
+
448
490
  state = RulesCore::StateCore.new(src, self, env)
449
491
  @core.process(state)
450
492
  return state.tokens