commonmarker-rouge 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6385d54bdf3c2d595f470e8a1bd57026a42dcb9f
4
- data.tar.gz: 6e8eec71ae524fcb564c8f3f720941ec64b54766
3
+ metadata.gz: 4f2d7482d2e0c5a47e20eb907765080128f91ab3
4
+ data.tar.gz: 60f42f343d12babbb9e7c13d21ae5d207d969c1c
5
5
  SHA512:
6
- metadata.gz: 8486f0ea6304f14b6d6498d53b1a1dc6d7e49730c7966e289c10f389aa7838494b5db67fd043268210d210cf9319de989399c4720de6cd1e8658947abddb12d1
7
- data.tar.gz: 6ef30167e5f636925a5d938d883fc1e03129006d08e472115774d14c989ba4d5a463bb15b3b90ebfd419bea76761ae330d985dd93766433e6fc6406d9d3ac791
6
+ metadata.gz: a9a4b020662d975972b57b6c21e3af6ae2675ab02b56ac4764feda4ed3c920fa6ad8bb45bb7ed15276693867220d4c5a163a948b1867de9e1813abd689557bdc
7
+ data.tar.gz: 8d3e11e5a0327f07348755afd339ae2afa2cfe5dd1144f6286746942cbe18e50604cb79e89c8a65aa55003488def04fe487145a334836f53398b7b64be062316
data/README.md CHANGED
@@ -32,11 +32,20 @@ CommonMarker::Rouge.render_html(content, [:SAFE, :SOURCEPOS])
32
32
  # use custom CommonMarker wrapper (must provide compatible render_doc)
33
33
  CommonMarker::Rouge.render_html(content, cmark_class: CommonMarkerWrapper)
34
34
 
35
- # use custom Rouge formatter
36
- CommonMarker::Rouge.render_html(content, formatter: Rouge::Formatters::HTMLLinewise)
35
+ # use custom Rouge formatter by class
36
+ CommonMarker::Rouge.render_html(content, formatter_class: Rouge::Formatters::HTMLLinewise)
37
+ # or by instance
38
+ CommonMarker::Rouge.render_html(content, formatter: Rouge::Formatters::HTMLTable.new(
39
+ Rouge::Formatters::HTML.new
40
+ ))
37
41
 
38
42
  # pass some options to Rouge
39
43
  CommonMarker::Rouge.render_html(content, options: { css_class: 'custom-class' })
44
+ # or
45
+ CommonMarker::Rouge.render_html(content, formatter: Rouge::Formatters::HTMLTable.new(
46
+ Rouge::Formatters::HTML.new, code_class: 'rouge-code'
47
+ ))
48
+
40
49
  ```
41
50
 
42
51
  ## License
@@ -8,19 +8,19 @@ module CommonMarker
8
8
  module Rouge
9
9
  module_function
10
10
 
11
- def render_doc(text, cmark_options = :DEFAULT, **highmark_options)
12
- cmark = highmark_options[:cmark_class] || ::CommonMarker
11
+ def render_doc(text, cmark_options = :DEFAULT, **cmr_options)
12
+ cmark = cmr_options[:cmark_class] || ::CommonMarker
13
13
 
14
14
  ast = cmark.render_doc(text, cmark_options)
15
- process_ast(ast, highmark_options)
15
+ process_ast(ast, cmr_options)
16
16
  ast
17
17
  end
18
18
 
19
- def render_html(text, cmark_options = :DEFAULT)
20
- render_doc(text, cmark_options).to_html
19
+ def render_html(text, cmark_options = :DEFAULT, **cmr_options)
20
+ render_doc(text, cmark_options, **cmr_options).to_html
21
21
  end
22
22
 
23
- def process_ast(ast, highmark_options)
23
+ def process_ast(ast, cmr_options)
24
24
  ast.walk do |node|
25
25
  if node.type == :code_block
26
26
  next if node.fence_info == ''
@@ -29,7 +29,18 @@ module CommonMarker
29
29
 
30
30
  lexer = ::Rouge::Lexer.find_fancy(node.fence_info) || ::Rouge::Lexers::PlainText.new
31
31
 
32
- formatter = (highmark_options[:formatter] || ::Rouge::Formatters::HTML).new(highmark_options[:options] || {})
32
+ formatter_class = cmr_options[:formatter_class]
33
+ formatter = cmr_options[:formatter]
34
+
35
+ # support format accepting class for a time being
36
+ if formatter.is_a? Class
37
+ formatter_class ||= formatter
38
+ formatter = nil
39
+ end
40
+
41
+ formatter_class ||= ::Rouge::Formatters::HTML
42
+
43
+ formatter ||= formatter_class.new(cmr_options[:options] || {})
33
44
 
34
45
  html = '<div class="highlighter-rouge language-' + CGI.escapeHTML(node.fence_info) + '">' + formatter.format(lexer.lex(source)) + '</div>'
35
46
 
@@ -1,5 +1,5 @@
1
1
  module CommonMarker
2
2
  module Rouge
3
- VERSION = '1.3.0'
3
+ VERSION = '1.4.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonmarker-rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Smirnov