commonmarker-rouge 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/commonmarker/rouge.rb +18 -7
- data/lib/commonmarker/rouge/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f2d7482d2e0c5a47e20eb907765080128f91ab3
|
4
|
+
data.tar.gz: 60f42f343d12babbb9e7c13d21ae5d207d969c1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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
|
data/lib/commonmarker/rouge.rb
CHANGED
@@ -8,19 +8,19 @@ module CommonMarker
|
|
8
8
|
module Rouge
|
9
9
|
module_function
|
10
10
|
|
11
|
-
def render_doc(text, cmark_options = :DEFAULT, **
|
12
|
-
cmark =
|
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,
|
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,
|
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
|
-
|
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
|
|