markdown_views 0.4.0 → 2.0.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.
@@ -0,0 +1,164 @@
1
+ .rouge-highlight table td { padding: 5px; }
2
+ .rouge-highlight table pre { margin: 0; }
3
+ .rouge-highlight {
4
+ color: #FFFFFF;
5
+ background-color: #231529;
6
+ }
7
+ .rouge-highlight .c, .rouge-highlight .cd, .rouge-highlight .cm, .rouge-highlight .c1, .rouge-highlight .cs {
8
+ color: #6D6E70;
9
+ font-style: italic;
10
+ }
11
+ .rouge-highlight .cp {
12
+ color: #41ff5b;
13
+ font-weight: bold;
14
+ font-style: italic;
15
+ }
16
+ .rouge-highlight .err {
17
+ color: #FFFFFF;
18
+ background-color: #CC0000;
19
+ }
20
+ .rouge-highlight .gr {
21
+ color: #FFFFFF;
22
+ background-color: #CC0000;
23
+ }
24
+ .rouge-highlight .k, .rouge-highlight .kd, .rouge-highlight .kv {
25
+ color: #FFF02A;
26
+ font-weight: bold;
27
+ }
28
+ .rouge-highlight .o, .rouge-highlight .ow {
29
+ color: #41ff5b;
30
+ }
31
+ .rouge-highlight .p, .rouge-highlight .pi {
32
+ color: #41ff5b;
33
+ }
34
+ .rouge-highlight .gd {
35
+ color: #CC0000;
36
+ }
37
+ .rouge-highlight .gi {
38
+ color: #3FB34F;
39
+ }
40
+ .rouge-highlight .ge {
41
+ font-style: italic;
42
+ }
43
+ .rouge-highlight .gs {
44
+ font-weight: bold;
45
+ }
46
+ .rouge-highlight .gt {
47
+ color: #FFFFFF;
48
+ background-color: #766DAF;
49
+ }
50
+ .rouge-highlight .gl {
51
+ color: #FFFFFF;
52
+ background-color: #766DAF;
53
+ }
54
+ .rouge-highlight .kc {
55
+ color: #9f93e6;
56
+ font-weight: bold;
57
+ }
58
+ .rouge-highlight .kn {
59
+ color: #FFFFFF;
60
+ font-weight: bold;
61
+ }
62
+ .rouge-highlight .kp {
63
+ color: #FFFFFF;
64
+ font-weight: bold;
65
+ }
66
+ .rouge-highlight .kr {
67
+ color: #FFFFFF;
68
+ font-weight: bold;
69
+ }
70
+ .rouge-highlight .gh {
71
+ color: #FFFFFF;
72
+ font-weight: bold;
73
+ }
74
+ .rouge-highlight .gu {
75
+ color: #FFFFFF;
76
+ font-weight: bold;
77
+ }
78
+ .rouge-highlight .kt {
79
+ color: #FAAF4C;
80
+ font-weight: bold;
81
+ }
82
+ .rouge-highlight .no {
83
+ color: #FAAF4C;
84
+ font-weight: bold;
85
+ }
86
+ .rouge-highlight .nc {
87
+ color: #FAAF4C;
88
+ font-weight: bold;
89
+ }
90
+ .rouge-highlight .nd {
91
+ color: #FAAF4C;
92
+ font-weight: bold;
93
+ }
94
+ .rouge-highlight .nn {
95
+ color: #FAAF4C;
96
+ font-weight: bold;
97
+ }
98
+ .rouge-highlight .bp {
99
+ color: #FAAF4C;
100
+ font-weight: bold;
101
+ }
102
+ .rouge-highlight .ne {
103
+ color: #FAAF4C;
104
+ font-weight: bold;
105
+ }
106
+ .rouge-highlight .nl {
107
+ color: #9f93e6;
108
+ font-weight: bold;
109
+ }
110
+ .rouge-highlight .nt {
111
+ color: #9f93e6;
112
+ font-weight: bold;
113
+ }
114
+ .rouge-highlight .m, .rouge-highlight .mf, .rouge-highlight .mh, .rouge-highlight .mi, .rouge-highlight .il, .rouge-highlight .mo, .rouge-highlight .mb, .rouge-highlight .mx {
115
+ color: #9f93e6;
116
+ font-weight: bold;
117
+ }
118
+ .rouge-highlight .ld {
119
+ color: #9f93e6;
120
+ font-weight: bold;
121
+ }
122
+ .rouge-highlight .ss {
123
+ color: #9f93e6;
124
+ font-weight: bold;
125
+ }
126
+ .rouge-highlight .s, .rouge-highlight .sb, .rouge-highlight .sd, .rouge-highlight .s2, .rouge-highlight .sh, .rouge-highlight .sx, .rouge-highlight .sr, .rouge-highlight .s1 {
127
+ color: #fff0a6;
128
+ font-weight: bold;
129
+ }
130
+ .rouge-highlight .se {
131
+ color: #FAAF4C;
132
+ font-weight: bold;
133
+ }
134
+ .rouge-highlight .sc {
135
+ color: #FAAF4C;
136
+ font-weight: bold;
137
+ }
138
+ .rouge-highlight .si {
139
+ color: #FAAF4C;
140
+ font-weight: bold;
141
+ }
142
+ .rouge-highlight .nb {
143
+ font-weight: bold;
144
+ }
145
+ .rouge-highlight .ni {
146
+ color: #999999;
147
+ font-weight: bold;
148
+ }
149
+ .rouge-highlight .w {
150
+ color: #BBBBBB;
151
+ }
152
+ .rouge-highlight .nf {
153
+ color: #41ff5b;
154
+ }
155
+ .rouge-highlight .py {
156
+ color: #41ff5b;
157
+ }
158
+ .rouge-highlight .na {
159
+ color: #41ff5b;
160
+ }
161
+ .rouge-highlight .nv, .rouge-highlight .vc, .rouge-highlight .vg, .rouge-highlight .vi {
162
+ color: #41ff5b;
163
+ font-weight: bold;
164
+ }
@@ -1,8 +1,6 @@
1
- # require 'active_support/core_ext/module/attribute_accessors'
2
1
  require 'action_view'
3
- require 'cgi'
4
- require 'coderay'
5
- require 'redcarpet'
2
+ require 'commonmarker'
3
+ require 'rouge'
6
4
 
7
5
  %w(config engine handler renderer version).each do |f|
8
6
  require "markdown_views/#{f}"
@@ -5,34 +5,26 @@ module MarkdownViews
5
5
  mattr_accessor :preprocessor
6
6
  self.preprocessor = :erb
7
7
 
8
+ mattr_accessor :extensions
9
+ self.extensions = %i(autolink strikethrough table tagfilter)
10
+
11
+ mattr_accessor :transformers
12
+ self.transformers = %i(code_blocks)
13
+
8
14
  mattr_accessor :rendering_opts
9
- self.rendering_opts = {
10
- # filter_html: true,
11
- hard_wrap: true,
12
- # link_attributes: {'data-popup'=> true},
13
- # no_styles: true,
14
- # safe_links_only: true,
15
- }
15
+ self.rendering_opts = %i(UNSAFE GITHUB_PRE_LANG HARDBREAKS TABLE_PREFER_STYLE_ATTRIBUTES)
16
+ # DEFAULT UNSAFE GITHUB_PRE_LANG HARDBREAKS NOBREAKS SOURCEPOS
17
+ # TABLE_PREFER_STYLE_ATTRIBUTES FULL_INFO_STRING
16
18
 
17
- mattr_accessor :markdown_opts
18
- self.markdown_opts = {
19
- autolink: true,
20
- disable_indented_code_blocks: true,
21
- fenced_code_blocks: true,
22
- lax_spacing: true,
23
- no_intra_emphasis: true,
24
- space_after_headers: true,
25
- strikethrough: true,
26
- tables: true,
27
- }
19
+ mattr_accessor :parsing_opts
20
+ self.parsing_opts = %i(UNSAFE SMART VALIDATE_UTF8)
21
+ # DEFAULT, UNSAFE, FOOTNOTES, LIBERAL_HTML_TAG, SMART
22
+ # STRIKETHROUGH_DOUBLE_TILDE, VALIDATE_UTF8
28
23
 
29
- mattr_accessor :coderay_opts
30
- self.coderay_opts = {
31
- bold_every: false,
32
- css: :class,
33
- line_number_anchors: false,
34
- line_numbers: false,
24
+ mattr_accessor :rouge_opts
25
+ self.rouge_opts = {
26
+ formatter: Rouge::Formatters::HTML.new,
27
+ wrap: true,
35
28
  }
36
29
 
37
30
  end
38
-
@@ -4,49 +4,50 @@ module MarkdownViews
4
4
 
5
5
  def render(template)
6
6
  out = template.to_s
7
- out = strip_comments(out) if MarkdownViews.strip_comments
8
- out = renderer.render(out)
9
- out = strip_comments(out) if MarkdownViews.strip_comments
7
+ strip_comments!(out) if MarkdownViews.strip_comments
8
+ out = render_md(out)
9
+ strip_comments!(out) if MarkdownViews.strip_comments
10
10
  out.html_safe
11
11
  end
12
12
 
13
- def renderer
14
- @@renderer ||= begin
15
- r = ExtendedMarkdownHtml.new MarkdownViews.rendering_opts
16
- Redcarpet::Markdown.new r, MarkdownViews.markdown_opts
17
- end
13
+ # remainder all considered private
14
+
15
+ def render_md(input)
16
+ doc = CommonMarker.render_doc(input, MarkdownViews.parsing_opts, MarkdownViews.extensions)
17
+
18
+ MarkdownViews.transformers.each {|name| send("transform_#{name}", doc) }
19
+
20
+ doc.to_html(MarkdownViews.rendering_opts, MarkdownViews.extensions)
18
21
  end
19
22
 
20
- def strip_comments(input)
21
- input.gsub(/[ \t\r\n\f]*<!--(.*?)-->*/m, '')
23
+ def rouge_formatter
24
+ MarkdownViews.rouge_opts[:formatter] || Rouge::Formatters::HTML.new
22
25
  end
23
26
 
24
- end
25
- end
27
+ def strip_comments!(input)
28
+ input.gsub!(/[ \t\r\n\f]*<!--(.*?)-->*/m, '')
29
+ end
26
30
 
27
- class ExtendedMarkdownHtml < Redcarpet::Render::HTML
28
- include Redcarpet::Render::SmartyPants
31
+ def transform_code_blocks(doc)
32
+ doc.walk do |node|
33
+ next unless node.type == :code_block
34
+ next if node.fence_info == ''
29
35
 
30
- def block_code(text, language)
31
- language ||= 'text'
32
- html = CGI::unescapeHTML(text).sub(/\A[ \t\n\r]+/, '').sub(/[ \t\n\r]+\Z/, '')
33
- cr = CodeRay.scan(html, language).html(MarkdownViews.coderay_opts)
34
- %Q{<pre class="lang-#{language.to_s.gsub(/[^a-z0-9]/,'')}"><code class="CodeRay">#{cr.chomp}</code></pre>}
35
- end
36
+ lang = node.fence_info
37
+ code = node.string_content
38
+ lexer = Rouge::Lexer.find(lang) || Rouge::Lexers::PlainText
39
+ html = rouge_formatter.format(lexer.lex code).rstrip
40
+ if MarkdownViews.rouge_opts[:wrap]
41
+ html = %Q{<pre lang="#{lang.gsub(/[^a-z0-9_-]/,'')}"><code class="rouge-highlight">#{html}</code></pre>}
42
+ end
43
+
44
+ new_node = CommonMarker::Node.new(:html)
45
+ new_node.string_content = html
46
+ node.insert_before new_node
47
+ node.delete
48
+ end
49
+ end
36
50
 
37
- def table(header, body)
38
- <<-TBL
39
- <div class="table-responsive">
40
- <table class="table">
41
- <thead>
42
- #{header}
43
- </thead>
44
- <tbody>
45
- #{body}
46
- </tbody>
47
- </table>
48
- </div>
49
- TBL
50
51
  end
51
52
  end
52
53
  end
@@ -1,3 +1,3 @@
1
1
  module MarkdownViews
2
- VERSION = '0.4.0'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["thomas morgan"]
10
10
  spec.email = ["tm@iprog.com"]
11
11
  spec.summary = %q{Add .md template handler to Rails.}
12
- spec.description = %q{Makes Rails handle .md templates, with optional preprocessing of ERB, HAML, etc. Easily configurable; uses RedCarpet & CodeRay.}
12
+ spec.description = %q{Enables Rails handling of .md templates, with optional preprocessing of ERB, HAML, etc. Also provides a markdown() view helper. Uses CommonMarker & Rouge.}
13
13
  spec.homepage = "https://github.com/zarqman/markdown_views"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'redcarpet', '~> 3.1'
22
- spec.add_dependency 'coderay', '~> 1.1'
23
- spec.add_dependency 'actionpack', '>= 4.0', '< 6'
21
+ spec.add_dependency 'commonmarker', '~> 0.18.2'
22
+ spec.add_dependency 'rouge', '~> 3.3.0'
23
+ spec.add_dependency 'actionpack', '>= 5.0', '< 6'
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.5"
26
26
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,50 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-07 00:00:00.000000000 Z
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: redcarpet
14
+ name: commonmarker
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: 0.18.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: 0.18.2
27
27
  - !ruby/object:Gem::Dependency
28
- name: coderay
28
+ name: rouge
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: 3.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: 3.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: actionpack
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4.0'
47
+ version: '5.0'
48
48
  - - "<"
49
49
  - !ruby/object:Gem::Version
50
50
  version: '6'
@@ -54,7 +54,7 @@ dependencies:
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: '4.0'
57
+ version: '5.0'
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '6'
@@ -86,8 +86,8 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
- description: Makes Rails handle .md templates, with optional preprocessing of ERB,
90
- HAML, etc. Easily configurable; uses RedCarpet & CodeRay.
89
+ description: Enables Rails handling of .md templates, with optional preprocessing
90
+ of ERB, HAML, etc. Also provides a markdown() view helper. Uses CommonMarker & Rouge.
91
91
  email:
92
92
  - tm@iprog.com
93
93
  executables: []
@@ -99,7 +99,23 @@ files:
99
99
  - LICENSE.txt
100
100
  - README.md
101
101
  - Rakefile
102
- - app/assets/stylesheets/coderay.css
102
+ - app/assets/stylesheets/rouge.base16.dark.css
103
+ - app/assets/stylesheets/rouge.base16.light.css
104
+ - app/assets/stylesheets/rouge.base16.monokai.dark.css
105
+ - app/assets/stylesheets/rouge.base16.monokai.light.css
106
+ - app/assets/stylesheets/rouge.base16.solarized.dark.css
107
+ - app/assets/stylesheets/rouge.base16.solarized.light.css
108
+ - app/assets/stylesheets/rouge.colorful.css
109
+ - app/assets/stylesheets/rouge.github.css
110
+ - app/assets/stylesheets/rouge.gruvbox.dark.css
111
+ - app/assets/stylesheets/rouge.gruvbox.light.css
112
+ - app/assets/stylesheets/rouge.igorpro.css
113
+ - app/assets/stylesheets/rouge.molokai.css
114
+ - app/assets/stylesheets/rouge.monokai.css
115
+ - app/assets/stylesheets/rouge.monokai.sublime.css
116
+ - app/assets/stylesheets/rouge.pastie.css
117
+ - app/assets/stylesheets/rouge.thankful_eyes.css
118
+ - app/assets/stylesheets/rouge.tulip.css
103
119
  - app/helpers/markdown_views_helper.rb
104
120
  - lib/markdown_views.rb
105
121
  - lib/markdown_views/config.rb
@@ -128,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
144
  version: '0'
129
145
  requirements: []
130
146
  rubyforge_project:
131
- rubygems_version: 2.6.12
147
+ rubygems_version: 2.7.8
132
148
  signing_key:
133
149
  specification_version: 4
134
150
  summary: Add .md template handler to Rails.