markdown_views 2.4.1 → 3.1.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/Gemfile.lock +97 -91
- data/README.md +17 -11
- data/Rakefile +5 -5
- data/app/assets/stylesheets/rouge.base16.dark.css +43 -30
- data/app/assets/stylesheets/rouge.base16.light.css +42 -29
- data/app/assets/stylesheets/rouge.base16.monokai.dark.css +16 -3
- data/app/assets/stylesheets/rouge.base16.monokai.light.css +16 -3
- data/app/assets/stylesheets/rouge.base16.solarized.dark.css +16 -3
- data/app/assets/stylesheets/rouge.base16.solarized.light.css +16 -3
- data/app/assets/stylesheets/rouge.bw.css +70 -0
- data/app/assets/stylesheets/rouge.colorful.css +12 -4
- data/app/assets/stylesheets/rouge.github.dark.css +116 -0
- data/app/assets/stylesheets/rouge.github.light.css +116 -0
- data/app/assets/stylesheets/rouge.gruvbox.dark.css +16 -3
- data/app/assets/stylesheets/rouge.gruvbox.light.css +16 -3
- data/app/assets/stylesheets/rouge.igorpro.css +15 -2
- data/app/assets/stylesheets/rouge.molokai.css +8 -5
- data/app/assets/stylesheets/rouge.monokai.css +12 -5
- data/app/assets/stylesheets/rouge.monokai.sublime.css +23 -7
- data/app/assets/stylesheets/rouge.pastie.css +13 -5
- data/app/assets/stylesheets/rouge.thankful_eyes.css +13 -6
- data/app/assets/stylesheets/rouge.tulip.css +13 -6
- data/lib/markdown_views/config.rb +23 -7
- data/lib/markdown_views/handler.rb +0 -21
- data/lib/markdown_views/renderer.rb +24 -7
- data/lib/markdown_views/version.rb +1 -1
- data/lib/markdown_views.rb +2 -5
- data/markdown_views.gemspec +6 -3
- data/test/config_test.rb +70 -0
- data/test/render_test.rb +50 -0
- data/test/strip_comments_test.rb +0 -6
- data/test/test_helper.rb +16 -0
- metadata +34 -20
- data/app/assets/stylesheets/rouge.github.css +0 -209
@@ -1,6 +1,6 @@
|
|
1
1
|
.rouge-highlight table td { padding: 5px; }
|
2
2
|
.rouge-highlight table pre { margin: 0; }
|
3
|
-
.rouge-highlight .c, .rouge-highlight .cd {
|
3
|
+
.rouge-highlight .c, .rouge-highlight .ch, .rouge-highlight .cd, .rouge-highlight .cpf {
|
4
4
|
color: #75715e;
|
5
5
|
font-style: italic;
|
6
6
|
}
|
@@ -34,7 +34,10 @@
|
|
34
34
|
background-color: #493131;
|
35
35
|
}
|
36
36
|
.rouge-highlight .ge {
|
37
|
-
|
37
|
+
font-style: italic;
|
38
|
+
}
|
39
|
+
.rouge-highlight .ges {
|
40
|
+
font-weight: bold;
|
38
41
|
font-style: italic;
|
39
42
|
}
|
40
43
|
.rouge-highlight .gr {
|
@@ -115,6 +118,10 @@
|
|
115
118
|
.rouge-highlight .se {
|
116
119
|
color: #ae81ff;
|
117
120
|
}
|
121
|
+
.rouge-highlight .sa {
|
122
|
+
color: #66d9ef;
|
123
|
+
font-weight: bold;
|
124
|
+
}
|
118
125
|
.rouge-highlight .sb {
|
119
126
|
color: #e6db74;
|
120
127
|
}
|
@@ -145,7 +152,7 @@
|
|
145
152
|
.rouge-highlight .ss {
|
146
153
|
color: #e6db74;
|
147
154
|
}
|
148
|
-
.rouge-highlight .s {
|
155
|
+
.rouge-highlight .s, .rouge-highlight .dl {
|
149
156
|
color: #e6db74;
|
150
157
|
}
|
151
158
|
.rouge-highlight .na {
|
@@ -163,7 +170,7 @@
|
|
163
170
|
color: #a6e22e;
|
164
171
|
font-weight: bold;
|
165
172
|
}
|
166
|
-
.rouge-highlight .nf {
|
173
|
+
.rouge-highlight .nf, .rouge-highlight .fm {
|
167
174
|
color: #a6e22e;
|
168
175
|
font-weight: bold;
|
169
176
|
}
|
@@ -191,7 +198,7 @@
|
|
191
198
|
.rouge-highlight .vi {
|
192
199
|
color: #f8f8f2;
|
193
200
|
}
|
194
|
-
.rouge-highlight .nv {
|
201
|
+
.rouge-highlight .nv, .rouge-highlight .vm {
|
195
202
|
color: #f8f8f2;
|
196
203
|
}
|
197
204
|
.rouge-highlight .w {
|
@@ -12,7 +12,15 @@
|
|
12
12
|
.rouge-highlight .gp {
|
13
13
|
color: #555555;
|
14
14
|
}
|
15
|
+
.rouge-highlight .ge {
|
16
|
+
font-style: italic;
|
17
|
+
}
|
18
|
+
.rouge-highlight .ges {
|
19
|
+
font-weight: bold;
|
20
|
+
font-style: italic;
|
21
|
+
}
|
15
22
|
.rouge-highlight .gs {
|
23
|
+
font-weight: bold;
|
16
24
|
}
|
17
25
|
.rouge-highlight .gu {
|
18
26
|
color: #aaaaaa;
|
@@ -32,7 +40,7 @@
|
|
32
40
|
.rouge-highlight .cs {
|
33
41
|
color: #75715e;
|
34
42
|
}
|
35
|
-
.rouge-highlight .c, .rouge-highlight .cd {
|
43
|
+
.rouge-highlight .c, .rouge-highlight .ch, .rouge-highlight .cd, .rouge-highlight .cpf {
|
36
44
|
color: #75715e;
|
37
45
|
}
|
38
46
|
.rouge-highlight .err {
|
@@ -50,9 +58,6 @@
|
|
50
58
|
.rouge-highlight .gi {
|
51
59
|
color: #49483e;
|
52
60
|
}
|
53
|
-
.rouge-highlight .ge {
|
54
|
-
color: #49483e;
|
55
|
-
}
|
56
61
|
.rouge-highlight .kc {
|
57
62
|
color: #66d9ef;
|
58
63
|
}
|
@@ -116,7 +121,7 @@
|
|
116
121
|
.rouge-highlight .s1 {
|
117
122
|
color: #e6db74;
|
118
123
|
}
|
119
|
-
.rouge-highlight .s {
|
124
|
+
.rouge-highlight .s, .rouge-highlight .sa, .rouge-highlight .dl {
|
120
125
|
color: #e6db74;
|
121
126
|
}
|
122
127
|
.rouge-highlight .na {
|
@@ -131,41 +136,52 @@
|
|
131
136
|
.rouge-highlight .ne {
|
132
137
|
color: #a6e22e;
|
133
138
|
}
|
134
|
-
.rouge-highlight .nf {
|
139
|
+
.rouge-highlight .nf, .rouge-highlight .fm {
|
135
140
|
color: #a6e22e;
|
136
141
|
}
|
137
142
|
.rouge-highlight .vc {
|
138
143
|
color: #ffffff;
|
144
|
+
background-color: #272822;
|
139
145
|
}
|
140
146
|
.rouge-highlight .nn {
|
141
147
|
color: #ffffff;
|
148
|
+
background-color: #272822;
|
142
149
|
}
|
143
150
|
.rouge-highlight .nl {
|
144
151
|
color: #ffffff;
|
152
|
+
background-color: #272822;
|
145
153
|
}
|
146
154
|
.rouge-highlight .ni {
|
147
155
|
color: #ffffff;
|
156
|
+
background-color: #272822;
|
148
157
|
}
|
149
158
|
.rouge-highlight .bp {
|
150
159
|
color: #ffffff;
|
160
|
+
background-color: #272822;
|
151
161
|
}
|
152
162
|
.rouge-highlight .vg {
|
153
163
|
color: #ffffff;
|
164
|
+
background-color: #272822;
|
154
165
|
}
|
155
166
|
.rouge-highlight .vi {
|
156
167
|
color: #ffffff;
|
168
|
+
background-color: #272822;
|
157
169
|
}
|
158
|
-
.rouge-highlight .nv {
|
170
|
+
.rouge-highlight .nv, .rouge-highlight .vm {
|
159
171
|
color: #ffffff;
|
172
|
+
background-color: #272822;
|
160
173
|
}
|
161
174
|
.rouge-highlight .w {
|
162
175
|
color: #ffffff;
|
176
|
+
background-color: #272822;
|
163
177
|
}
|
164
178
|
.rouge-highlight {
|
165
179
|
color: #ffffff;
|
180
|
+
background-color: #272822;
|
166
181
|
}
|
167
182
|
.rouge-highlight .n, .rouge-highlight .py, .rouge-highlight .nx {
|
168
183
|
color: #ffffff;
|
184
|
+
background-color: #272822;
|
169
185
|
}
|
170
186
|
.rouge-highlight .ow {
|
171
187
|
color: #f92672;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
.rouge-highlight table td { padding: 5px; }
|
2
2
|
.rouge-highlight table pre { margin: 0; }
|
3
|
-
.rouge-highlight .c, .rouge-highlight .cd, .rouge-highlight .cm, .rouge-highlight .c1 {
|
3
|
+
.rouge-highlight .c, .rouge-highlight .ch, .rouge-highlight .cd, .rouge-highlight .cm, .rouge-highlight .cpf, .rouge-highlight .c1 {
|
4
4
|
color: #888888;
|
5
5
|
}
|
6
6
|
.rouge-highlight .cp {
|
@@ -36,6 +36,10 @@
|
|
36
36
|
.rouge-highlight .ge {
|
37
37
|
font-style: italic;
|
38
38
|
}
|
39
|
+
.rouge-highlight .ges {
|
40
|
+
font-weight: bold;
|
41
|
+
font-style: italic;
|
42
|
+
}
|
39
43
|
.rouge-highlight .gs {
|
40
44
|
font-weight: bold;
|
41
45
|
}
|
@@ -62,14 +66,18 @@
|
|
62
66
|
color: #888888;
|
63
67
|
font-weight: bold;
|
64
68
|
}
|
65
|
-
.rouge-highlight .m, .rouge-highlight .
|
69
|
+
.rouge-highlight .m, .rouge-highlight .mb, .rouge-highlight .mf, .rouge-highlight .mh, .rouge-highlight .mi, .rouge-highlight .il, .rouge-highlight .mo, .rouge-highlight .mx {
|
66
70
|
color: #0000dd;
|
67
71
|
font-weight: bold;
|
68
72
|
}
|
69
|
-
.rouge-highlight .s, .rouge-highlight .sb, .rouge-highlight .sc, .rouge-highlight .sd, .rouge-highlight .s2, .rouge-highlight .sh, .rouge-highlight .s1 {
|
73
|
+
.rouge-highlight .s, .rouge-highlight .sb, .rouge-highlight .sc, .rouge-highlight .dl, .rouge-highlight .sd, .rouge-highlight .s2, .rouge-highlight .sh, .rouge-highlight .s1 {
|
70
74
|
color: #dd2200;
|
71
75
|
background-color: #fff0f0;
|
72
76
|
}
|
77
|
+
.rouge-highlight .sa {
|
78
|
+
color: #008800;
|
79
|
+
font-weight: bold;
|
80
|
+
}
|
73
81
|
.rouge-highlight .se {
|
74
82
|
color: #0044dd;
|
75
83
|
background-color: #fff0f0;
|
@@ -110,7 +118,7 @@
|
|
110
118
|
color: #bb0066;
|
111
119
|
font-weight: bold;
|
112
120
|
}
|
113
|
-
.rouge-highlight .nf {
|
121
|
+
.rouge-highlight .nf, .rouge-highlight .fm {
|
114
122
|
color: #0066bb;
|
115
123
|
font-weight: bold;
|
116
124
|
}
|
@@ -129,7 +137,7 @@
|
|
129
137
|
color: #bb0066;
|
130
138
|
font-weight: bold;
|
131
139
|
}
|
132
|
-
.rouge-highlight .nv, .rouge-highlight .vc {
|
140
|
+
.rouge-highlight .nv, .rouge-highlight .vc, .rouge-highlight .vm {
|
133
141
|
color: #336699;
|
134
142
|
}
|
135
143
|
.rouge-highlight .vg {
|
@@ -12,14 +12,13 @@
|
|
12
12
|
color: #a8e1fe;
|
13
13
|
font-weight: bold;
|
14
14
|
}
|
15
|
-
.rouge-highlight .c, .rouge-highlight .cd, .rouge-highlight .cm, .rouge-highlight .c1, .rouge-highlight .cs {
|
15
|
+
.rouge-highlight .c, .rouge-highlight .ch, .rouge-highlight .cd, .rouge-highlight .cm, .rouge-highlight .cpf, .rouge-highlight .c1, .rouge-highlight .cs {
|
16
16
|
color: #6c8b9f;
|
17
17
|
font-style: italic;
|
18
18
|
}
|
19
19
|
.rouge-highlight .cp {
|
20
20
|
color: #b2fd6d;
|
21
21
|
font-weight: bold;
|
22
|
-
font-style: italic;
|
23
22
|
}
|
24
23
|
.rouge-highlight .err {
|
25
24
|
color: #fefeec;
|
@@ -50,6 +49,10 @@
|
|
50
49
|
.rouge-highlight .ge {
|
51
50
|
font-style: italic;
|
52
51
|
}
|
52
|
+
.rouge-highlight .ges {
|
53
|
+
font-weight: bold;
|
54
|
+
font-style: italic;
|
55
|
+
}
|
53
56
|
.rouge-highlight .gs {
|
54
57
|
font-weight: bold;
|
55
58
|
}
|
@@ -117,7 +120,7 @@
|
|
117
120
|
color: #ffb000;
|
118
121
|
font-weight: bold;
|
119
122
|
}
|
120
|
-
.rouge-highlight .m, .rouge-highlight .
|
123
|
+
.rouge-highlight .m, .rouge-highlight .mb, .rouge-highlight .mf, .rouge-highlight .mh, .rouge-highlight .mi, .rouge-highlight .il, .rouge-highlight .mo, .rouge-highlight .mx {
|
121
124
|
color: #f696db;
|
122
125
|
font-weight: bold;
|
123
126
|
}
|
@@ -129,10 +132,14 @@
|
|
129
132
|
color: #f696db;
|
130
133
|
font-weight: bold;
|
131
134
|
}
|
132
|
-
.rouge-highlight .s, .rouge-highlight .sb, .rouge-highlight .sd, .rouge-highlight .s2, .rouge-highlight .sh, .rouge-highlight .sx, .rouge-highlight .sr, .rouge-highlight .s1 {
|
135
|
+
.rouge-highlight .s, .rouge-highlight .sb, .rouge-highlight .dl, .rouge-highlight .sd, .rouge-highlight .s2, .rouge-highlight .sh, .rouge-highlight .sx, .rouge-highlight .sr, .rouge-highlight .s1 {
|
133
136
|
color: #fff0a6;
|
134
137
|
font-weight: bold;
|
135
138
|
}
|
139
|
+
.rouge-highlight .sa {
|
140
|
+
color: #f6dd62;
|
141
|
+
font-weight: bold;
|
142
|
+
}
|
136
143
|
.rouge-highlight .se {
|
137
144
|
color: #4df4ff;
|
138
145
|
font-weight: bold;
|
@@ -158,7 +165,7 @@
|
|
158
165
|
.rouge-highlight .go {
|
159
166
|
color: #BBBBBB;
|
160
167
|
}
|
161
|
-
.rouge-highlight .nf {
|
168
|
+
.rouge-highlight .nf, .rouge-highlight .fm {
|
162
169
|
color: #a8e1fe;
|
163
170
|
}
|
164
171
|
.rouge-highlight .py {
|
@@ -167,7 +174,7 @@
|
|
167
174
|
.rouge-highlight .na {
|
168
175
|
color: #a8e1fe;
|
169
176
|
}
|
170
|
-
.rouge-highlight .nv, .rouge-highlight .vc, .rouge-highlight .vg, .rouge-highlight .vi {
|
177
|
+
.rouge-highlight .nv, .rouge-highlight .vc, .rouge-highlight .vg, .rouge-highlight .vi, .rouge-highlight .vm {
|
171
178
|
color: #a8e1fe;
|
172
179
|
font-weight: bold;
|
173
180
|
}
|
@@ -4,14 +4,13 @@
|
|
4
4
|
color: #FFFFFF;
|
5
5
|
background-color: #231529;
|
6
6
|
}
|
7
|
-
.rouge-highlight .c, .rouge-highlight .cd, .rouge-highlight .cm, .rouge-highlight .c1, .rouge-highlight .cs {
|
7
|
+
.rouge-highlight .c, .rouge-highlight .ch, .rouge-highlight .cd, .rouge-highlight .cm, .rouge-highlight .cpf, .rouge-highlight .c1, .rouge-highlight .cs {
|
8
8
|
color: #6D6E70;
|
9
9
|
font-style: italic;
|
10
10
|
}
|
11
11
|
.rouge-highlight .cp {
|
12
12
|
color: #41ff5b;
|
13
13
|
font-weight: bold;
|
14
|
-
font-style: italic;
|
15
14
|
}
|
16
15
|
.rouge-highlight .err {
|
17
16
|
color: #FFFFFF;
|
@@ -40,6 +39,10 @@
|
|
40
39
|
.rouge-highlight .ge {
|
41
40
|
font-style: italic;
|
42
41
|
}
|
42
|
+
.rouge-highlight .ges {
|
43
|
+
font-weight: bold;
|
44
|
+
font-style: italic;
|
45
|
+
}
|
43
46
|
.rouge-highlight .gs {
|
44
47
|
font-weight: bold;
|
45
48
|
}
|
@@ -111,7 +114,7 @@
|
|
111
114
|
color: #9f93e6;
|
112
115
|
font-weight: bold;
|
113
116
|
}
|
114
|
-
.rouge-highlight .m, .rouge-highlight .
|
117
|
+
.rouge-highlight .m, .rouge-highlight .mb, .rouge-highlight .mf, .rouge-highlight .mh, .rouge-highlight .mi, .rouge-highlight .il, .rouge-highlight .mo, .rouge-highlight .mx {
|
115
118
|
color: #9f93e6;
|
116
119
|
font-weight: bold;
|
117
120
|
}
|
@@ -123,10 +126,14 @@
|
|
123
126
|
color: #9f93e6;
|
124
127
|
font-weight: bold;
|
125
128
|
}
|
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 {
|
129
|
+
.rouge-highlight .s, .rouge-highlight .sb, .rouge-highlight .dl, .rouge-highlight .sd, .rouge-highlight .s2, .rouge-highlight .sh, .rouge-highlight .sx, .rouge-highlight .sr, .rouge-highlight .s1 {
|
127
130
|
color: #fff0a6;
|
128
131
|
font-weight: bold;
|
129
132
|
}
|
133
|
+
.rouge-highlight .sa {
|
134
|
+
color: #FFF02A;
|
135
|
+
font-weight: bold;
|
136
|
+
}
|
130
137
|
.rouge-highlight .se {
|
131
138
|
color: #FAAF4C;
|
132
139
|
font-weight: bold;
|
@@ -149,7 +156,7 @@
|
|
149
156
|
.rouge-highlight .w {
|
150
157
|
color: #BBBBBB;
|
151
158
|
}
|
152
|
-
.rouge-highlight .nf {
|
159
|
+
.rouge-highlight .nf, .rouge-highlight .fm {
|
153
160
|
color: #41ff5b;
|
154
161
|
}
|
155
162
|
.rouge-highlight .py {
|
@@ -158,7 +165,7 @@
|
|
158
165
|
.rouge-highlight .na {
|
159
166
|
color: #41ff5b;
|
160
167
|
}
|
161
|
-
.rouge-highlight .nv, .rouge-highlight .vc, .rouge-highlight .vg, .rouge-highlight .vi {
|
168
|
+
.rouge-highlight .nv, .rouge-highlight .vc, .rouge-highlight .vg, .rouge-highlight .vi, .rouge-highlight .vm {
|
162
169
|
color: #41ff5b;
|
163
170
|
font-weight: bold;
|
164
171
|
}
|
@@ -6,20 +6,36 @@ module MarkdownViews
|
|
6
6
|
self.preprocessor = :erb
|
7
7
|
|
8
8
|
mattr_accessor :extensions
|
9
|
-
self.extensions =
|
9
|
+
self.extensions = Commonmarker::Config::OPTIONS[:extension].merge(
|
10
|
+
strikethrough: true,
|
11
|
+
tagfilter: true,
|
12
|
+
table: true,
|
13
|
+
autolink: true,
|
14
|
+
tasklist: false,
|
15
|
+
header_ids: nil,
|
16
|
+
shortcodes: false,
|
17
|
+
)
|
10
18
|
|
11
19
|
mattr_accessor :transformers
|
12
20
|
self.transformers = %i(code_blocks)
|
13
21
|
|
14
22
|
mattr_accessor :rendering_opts
|
15
|
-
self.rendering_opts =
|
16
|
-
|
17
|
-
|
23
|
+
self.rendering_opts = Commonmarker::Config::OPTIONS[:render].merge(
|
24
|
+
unsafe: true,
|
25
|
+
github_pre_lang: true,
|
26
|
+
hardbreaks: true,
|
27
|
+
escaped_char_spans: false,
|
28
|
+
)
|
18
29
|
|
19
30
|
mattr_accessor :parsing_opts
|
20
|
-
self.parsing_opts =
|
21
|
-
|
22
|
-
|
31
|
+
self.parsing_opts = Commonmarker::Config::OPTIONS[:parse].merge(
|
32
|
+
smart: true,
|
33
|
+
)
|
34
|
+
|
35
|
+
mattr_accessor :plugins
|
36
|
+
self.plugins = Commonmarker::Config::PLUGINS.merge(
|
37
|
+
syntax_highlighter: nil,
|
38
|
+
)
|
23
39
|
|
24
40
|
mattr_accessor :rouge_opts
|
25
41
|
self.rouge_opts = {
|
@@ -1,25 +1,4 @@
|
|
1
1
|
module MarkdownViews
|
2
|
-
class Handler52
|
3
|
-
class << self
|
4
|
-
|
5
|
-
def call(template)
|
6
|
-
source = preprocessor.call(template)
|
7
|
-
|
8
|
-
<<-R1
|
9
|
-
MarkdownViews::Renderer.render(begin;#{source};end)
|
10
|
-
R1
|
11
|
-
end
|
12
|
-
|
13
|
-
def preprocessor
|
14
|
-
@@preprocessor ||= begin
|
15
|
-
pp = MarkdownViews.preprocessor || :raw
|
16
|
-
ActionView::Template.registered_template_handler(pp) || raise('Unknown template handler')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
2
|
class Handler
|
24
3
|
class << self
|
25
4
|
|
@@ -13,11 +13,26 @@ module MarkdownViews
|
|
13
13
|
# remainder all considered private
|
14
14
|
|
15
15
|
def render_md(input)
|
16
|
-
doc =
|
16
|
+
doc = Commonmarker.parse(input, options: {
|
17
|
+
extension: MarkdownViews.extensions,
|
18
|
+
parse: MarkdownViews.parsing_opts,
|
19
|
+
})
|
17
20
|
|
18
|
-
MarkdownViews.transformers.
|
21
|
+
if MarkdownViews.transformers.include? :code_blocks
|
22
|
+
code_blocks = transform_code_blocks(doc)
|
23
|
+
end
|
19
24
|
|
20
|
-
doc.to_html(
|
25
|
+
out = doc.to_html(
|
26
|
+
options: {
|
27
|
+
extension: MarkdownViews.extensions,
|
28
|
+
render: MarkdownViews.rendering_opts,
|
29
|
+
},
|
30
|
+
plugins: MarkdownViews.plugins
|
31
|
+
)
|
32
|
+
code_blocks&.each do |uuid, cb|
|
33
|
+
out.sub! uuid, cb
|
34
|
+
end
|
35
|
+
out
|
21
36
|
end
|
22
37
|
|
23
38
|
def rouge_formatter
|
@@ -52,6 +67,7 @@ module MarkdownViews
|
|
52
67
|
end
|
53
68
|
|
54
69
|
def transform_code_blocks(doc)
|
70
|
+
code_blocks = {}
|
55
71
|
doc.walk do |node|
|
56
72
|
next unless node.type == :code_block
|
57
73
|
next if node.fence_info == ''
|
@@ -64,11 +80,12 @@ module MarkdownViews
|
|
64
80
|
html = %Q{<pre lang="#{lang.gsub(/[^a-z0-9_-]/,'')}"><code class="rouge-highlight">#{html}</code></pre>}
|
65
81
|
end
|
66
82
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
node.
|
83
|
+
uuid = SecureRandom.uuid
|
84
|
+
code_blocks[uuid] = html
|
85
|
+
new_node = Commonmarker::Node.new(:text, content: "#{uuid}\n")
|
86
|
+
node.replace new_node
|
71
87
|
end
|
88
|
+
code_blocks
|
72
89
|
end
|
73
90
|
|
74
91
|
end
|
data/lib/markdown_views.rb
CHANGED
@@ -2,13 +2,10 @@ require 'action_view'
|
|
2
2
|
require 'commonmarker'
|
3
3
|
require 'rails'
|
4
4
|
require 'rouge'
|
5
|
+
require 'securerandom'
|
5
6
|
|
6
7
|
%w(config engine handler renderer version).each do |f|
|
7
8
|
require "markdown_views/#{f}"
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
-
ActionView::Template.register_template_handler(:md, MarkdownViews::Handler52)
|
12
|
-
else
|
13
|
-
ActionView::Template.register_template_handler(:md, MarkdownViews::Handler)
|
14
|
-
end
|
11
|
+
ActionView::Template.register_template_handler(:md, MarkdownViews::Handler)
|
data/markdown_views.gemspec
CHANGED
@@ -18,9 +18,12 @@ 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.
|
22
|
-
|
23
|
-
spec.add_dependency '
|
21
|
+
spec.required_ruby_version = '~> 3.1'
|
22
|
+
|
23
|
+
spec.add_dependency 'commonmarker', '>= 1.1', '< 3.0'
|
24
|
+
spec.add_dependency 'rails', '>= 6.1', '< 8.1'
|
25
|
+
spec.add_dependency 'rouge', '~> 4'
|
26
|
+
spec.add_dependency 'securerandom'
|
24
27
|
|
25
28
|
spec.add_development_dependency "minitest-reporters"
|
26
29
|
spec.add_development_dependency "rake"
|
data/test/config_test.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ConfigTest < Minitest::Test
|
4
|
+
|
5
|
+
def test_extensions
|
6
|
+
processed = Commonmarker::Config.process_options(extension: MarkdownViews.extensions)[:extension]
|
7
|
+
expected = {
|
8
|
+
strikethrough: true,
|
9
|
+
tagfilter: true,
|
10
|
+
table: true,
|
11
|
+
autolink: true,
|
12
|
+
tasklist: false,
|
13
|
+
superscript: false,
|
14
|
+
# header_ids: '',
|
15
|
+
footnotes: false,
|
16
|
+
description_lists: false,
|
17
|
+
front_matter_delimiter: '',
|
18
|
+
multiline_block_quotes: false,
|
19
|
+
math_dollars: false,
|
20
|
+
math_code: false,
|
21
|
+
shortcodes: false,
|
22
|
+
wikilinks_title_before_pipe: false,
|
23
|
+
wikilinks_title_after_pipe: false,
|
24
|
+
underline: false,
|
25
|
+
spoiler: false,
|
26
|
+
greentext: false,
|
27
|
+
subscript: false,
|
28
|
+
}
|
29
|
+
assert_equal expected, processed
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_parsing_opts
|
33
|
+
processed = Commonmarker::Config.process_options(parse: MarkdownViews.parsing_opts)[:parse]
|
34
|
+
expected = {
|
35
|
+
smart: true,
|
36
|
+
default_info_string: '',
|
37
|
+
relaxed_tasklist_matching: false,
|
38
|
+
relaxed_autolinks: false,
|
39
|
+
}
|
40
|
+
assert_equal expected, processed
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_plugins
|
44
|
+
processed = Commonmarker::Config.process_plugins(MarkdownViews.plugins)
|
45
|
+
expected = {
|
46
|
+
syntax_highlighter: nil
|
47
|
+
}
|
48
|
+
assert_equal expected, processed
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_rendering_opts
|
52
|
+
processed = Commonmarker::Config.process_options(render: MarkdownViews.rendering_opts)[:render]
|
53
|
+
expected = {
|
54
|
+
hardbreaks: true,
|
55
|
+
github_pre_lang: true,
|
56
|
+
full_info_string: false,
|
57
|
+
width: 80,
|
58
|
+
unsafe: true,
|
59
|
+
escape: false,
|
60
|
+
sourcepos: false,
|
61
|
+
escaped_char_spans: false,
|
62
|
+
ignore_setext: false,
|
63
|
+
ignore_empty_links: false,
|
64
|
+
gfm_quirks: false,
|
65
|
+
prefer_fenced: false,
|
66
|
+
}
|
67
|
+
assert_equal expected, processed
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/test/render_test.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class RenderTest < Minitest::Test
|
4
|
+
|
5
|
+
def test_markdown
|
6
|
+
s = <<~MD
|
7
|
+
# header
|
8
|
+
this is *amazing*!
|
9
|
+
MD
|
10
|
+
o = <<~HTML
|
11
|
+
<h1>header</h1>
|
12
|
+
<p>this is <em>amazing</em>!</p>
|
13
|
+
HTML
|
14
|
+
assert_equal o, render(s)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_inline_html
|
18
|
+
s = <<~MD
|
19
|
+
---
|
20
|
+
<em>inline</em> html
|
21
|
+
MD
|
22
|
+
o = <<~HTML
|
23
|
+
<hr />
|
24
|
+
<p><em>inline</em> html</p>
|
25
|
+
HTML
|
26
|
+
assert_equal o, render(s)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_code_block
|
30
|
+
s = <<~MD
|
31
|
+
```ruby
|
32
|
+
def syntax_highlighting
|
33
|
+
'works too!'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
MD
|
37
|
+
o = <<~HTML
|
38
|
+
<pre lang="ruby"><code class="rouge-highlight"><span class="k">def</span> <span class="nf">syntax_highlighting</span>
|
39
|
+
<span class="s1">'works too!'</span>
|
40
|
+
<span class="k">end</span></code></pre>
|
41
|
+
HTML
|
42
|
+
assert_equal o, render(s)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def render(*args)
|
47
|
+
MarkdownViews::Renderer.render(*args)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/test/strip_comments_test.rb
CHANGED
@@ -53,10 +53,4 @@ class StripCommentsTest < Minitest::Test
|
|
53
53
|
MarkdownViews::Renderer.strip_comments(*args)
|
54
54
|
end
|
55
55
|
|
56
|
-
# hack to make diffs more understandable
|
57
|
-
# otherwise minitest sometimes truncates multi-lines diffs, making them unusable
|
58
|
-
def mu_pp(obj)
|
59
|
-
super obj.gsub("\n", '\n').gsub("\t", '\t')
|
60
|
-
end
|
61
|
-
|
62
56
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,3 +5,19 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
|
5
5
|
require "markdown_views"
|
6
6
|
|
7
7
|
require "minitest/autorun"
|
8
|
+
|
9
|
+
|
10
|
+
module TestHelpers
|
11
|
+
|
12
|
+
# hack to make diffs more understandable
|
13
|
+
# otherwise minitest sometimes truncates multi-lines diffs, making them unusable
|
14
|
+
def mu_pp(obj)
|
15
|
+
if obj.is_a? String
|
16
|
+
super obj.gsub("\n", '\n').gsub("\t", '\t')
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
Minitest::Test.include TestHelpers
|