redcarpet 1.10.1 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of redcarpet might be problematic. Click here for more details.
- data/ext/markdown.c +13 -2
- data/ext/redcarpet.c +3 -0
- data/ext/xhtml.c +54 -23
- data/ext/xhtml.h +1 -0
- data/lib/redcarpet.rb +4 -1
- data/redcarpet.gemspec +2 -2
- data/test/redcarpet_test.rb +12 -0
- metadata +5 -5
data/ext/markdown.c
CHANGED
@@ -24,6 +24,7 @@
|
|
24
24
|
#include <string.h>
|
25
25
|
#include <strings.h> /* for strncasecmp */
|
26
26
|
#include <ctype.h>
|
27
|
+
#include <stdio.h>
|
27
28
|
|
28
29
|
#define TEXT_UNIT 64 /* unit for the copy of the input buffer */
|
29
30
|
#define WORK_UNIT 64 /* block-level working buffer */
|
@@ -717,7 +718,8 @@ char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t
|
|
717
718
|
link_b = i;
|
718
719
|
|
719
720
|
/* looking for link end: ' " ) */
|
720
|
-
while (i < size && data[i] != '\'' && data[i] != '"' &&
|
721
|
+
while (i < size && data[i] != '\'' && data[i] != '"' &&
|
722
|
+
(data[i] != ')' || data[i - 1] == '\\'))
|
721
723
|
i++;
|
722
724
|
|
723
725
|
if (i >= size) goto cleanup;
|
@@ -728,7 +730,7 @@ char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t
|
|
728
730
|
i++;
|
729
731
|
title_b = i;
|
730
732
|
|
731
|
-
while (i < size && data[i] != ')') i++;
|
733
|
+
while (i < size && (data[i] != ')' || data[i - 1] == '\\')) i++;
|
732
734
|
if (i >= size) goto cleanup;
|
733
735
|
|
734
736
|
/* skipping whitespaces after title */
|
@@ -958,6 +960,15 @@ is_codefence(char *data, size_t size, struct buf *syntax)
|
|
958
960
|
if (i == size || data[i] != '}')
|
959
961
|
return 0;
|
960
962
|
|
963
|
+
/* strip all whitespace at the beggining and the end
|
964
|
+
* of the {} block */
|
965
|
+
while (syn > 0 && isspace(syntax->data[0])) {
|
966
|
+
syntax->data++; syn--;
|
967
|
+
}
|
968
|
+
|
969
|
+
while (syn > 0 && isspace(syntax->data[syn - 1]))
|
970
|
+
syn--;
|
971
|
+
|
961
972
|
i++;
|
962
973
|
} else {
|
963
974
|
while (i < size && !isspace(data[i])) {
|
data/ext/redcarpet.c
CHANGED
@@ -49,6 +49,9 @@ static void rb_redcarpet__get_flags(VALUE ruby_obj,
|
|
49
49
|
if (rb_funcall(ruby_obj, rb_intern("hard_wrap"), 0) == Qtrue)
|
50
50
|
render_flags |= XHTML_HARD_WRAP;
|
51
51
|
|
52
|
+
if (rb_funcall(ruby_obj, rb_intern("gh_blockcode"), 0) == Qtrue)
|
53
|
+
render_flags |= XHTML_GITHUB_BLOCKCODE;
|
54
|
+
|
52
55
|
/**
|
53
56
|
* Markdown extensions -- all disabled by default
|
54
57
|
*/
|
data/ext/xhtml.c
CHANGED
@@ -136,38 +136,66 @@ rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *op
|
|
136
136
|
static void
|
137
137
|
rndr_blockcode(struct buf *ob, struct buf *text, struct buf *lang, void *opaque)
|
138
138
|
{
|
139
|
-
static char *sh_lang = "bash";
|
140
|
-
struct buf lang_shebang = {0, 0, 0, 0, 0};
|
141
|
-
|
142
139
|
if (ob->size) bufputc(ob, '\n');
|
143
140
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
if (lang == NULL && text != NULL && text->size > 2) {
|
148
|
-
if (bufprefix(text, "#!/usr/bin/env ") == 0) {
|
149
|
-
size_t i = STRLEN("#!/usr/bin/env ");
|
141
|
+
if (lang && lang->size) {
|
142
|
+
size_t i = 0;
|
143
|
+
BUFPUTSL(ob, "<pre><code class=\"");
|
150
144
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
}
|
145
|
+
for (i = 0; i < lang->size; ++i) {
|
146
|
+
if (lang->data[i] == '.' && (i == 0 || isspace(lang->data[i - 1])))
|
147
|
+
continue;
|
155
148
|
|
156
|
-
lang
|
157
|
-
} else if (bufprefix(text, "#!/bin/sh") == 0 && isspace(text->data[STRLEN("#!/bin/sh")])) {
|
158
|
-
lang_shebang.data = sh_lang;
|
159
|
-
lang_shebang.size = strlen(sh_lang);
|
160
|
-
lang = &lang_shebang;
|
149
|
+
bufputc(ob, lang->data[i]);
|
161
150
|
}
|
162
|
-
|
151
|
+
|
152
|
+
BUFPUTSL(ob, "\">");
|
153
|
+
} else
|
154
|
+
BUFPUTSL(ob, "<pre><code>");
|
155
|
+
|
156
|
+
if (text)
|
157
|
+
lus_attr_escape(ob, text->data, text->size);
|
158
|
+
|
159
|
+
BUFPUTSL(ob, "</code></pre>\n");
|
160
|
+
}
|
161
|
+
|
162
|
+
/*
|
163
|
+
* GitHub style code block:
|
164
|
+
*
|
165
|
+
* <pre lang="LANG"><code>
|
166
|
+
* ...
|
167
|
+
* </pre></code>
|
168
|
+
*
|
169
|
+
* Unlike other parsers, we store the language identifier in the <pre>,
|
170
|
+
* and don't let the user generate custom classes.
|
171
|
+
*
|
172
|
+
* The language identifier in the <pre> block gets postprocessed and all
|
173
|
+
* the code inside gets syntax highlighted with Pygments. This is much safer
|
174
|
+
* than letting the user specify a CSS class for highlighting.
|
175
|
+
*
|
176
|
+
* Note that we only generate HTML for the first specifier.
|
177
|
+
* E.g.
|
178
|
+
* ~~~~ {.python .numbered} => <pre lang="python"><code>
|
179
|
+
*/
|
180
|
+
static void
|
181
|
+
rndr_blockcode_github(struct buf *ob, struct buf *text, struct buf *lang, void *opaque)
|
182
|
+
{
|
183
|
+
if (ob->size) bufputc(ob, '\n');
|
163
184
|
|
164
185
|
if (lang && lang->size) {
|
165
|
-
|
186
|
+
size_t i = 0;
|
187
|
+
BUFPUTSL(ob, "<pre lang=\"");
|
188
|
+
|
189
|
+
for (; i < lang->size; ++i)
|
190
|
+
if (isspace(lang->data[i]))
|
191
|
+
break;
|
192
|
+
|
166
193
|
if (lang->data[0] == '.')
|
167
|
-
bufput(ob, lang->data + 1,
|
194
|
+
bufput(ob, lang->data + 1, i - 1);
|
168
195
|
else
|
169
|
-
bufput(ob, lang->data,
|
170
|
-
|
196
|
+
bufput(ob, lang->data, i);
|
197
|
+
|
198
|
+
BUFPUTSL(ob, "\"><code>");
|
171
199
|
} else
|
172
200
|
BUFPUTSL(ob, "<pre><code>");
|
173
201
|
|
@@ -745,6 +773,9 @@ ups_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags)
|
|
745
773
|
|
746
774
|
if (render_flags & XHTML_SMARTYPANTS)
|
747
775
|
renderer->normal_text = rndr_smartypants;
|
776
|
+
|
777
|
+
if (render_flags & XHTML_GITHUB_BLOCKCODE)
|
778
|
+
renderer->blockcode = rndr_blockcode_github;
|
748
779
|
}
|
749
780
|
|
750
781
|
void
|
data/ext/xhtml.h
CHANGED
data/lib/redcarpet.rb
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
# end
|
27
27
|
#
|
28
28
|
class Redcarpet
|
29
|
-
VERSION = '1.
|
29
|
+
VERSION = '1.11.0'
|
30
30
|
|
31
31
|
# Original Markdown formatted text.
|
32
32
|
attr_reader :text
|
@@ -52,6 +52,9 @@ class Redcarpet
|
|
52
52
|
# Disable superscript and relaxed emphasis processing.
|
53
53
|
attr_accessor :strict
|
54
54
|
|
55
|
+
# Generate safer HTML for code blocks (no custom CSS classes)
|
56
|
+
attr_accessor :gh_blockcode
|
57
|
+
|
55
58
|
# Don't make hyperlinks from <tt>[][]</tt> links that have unknown URL types.
|
56
59
|
attr_accessor :safelink
|
57
60
|
|
data/redcarpet.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'redcarpet'
|
3
|
-
s.version = '1.
|
3
|
+
s.version = '1.11.0'
|
4
4
|
s.summary = "Ruby bindings for libupskirt"
|
5
5
|
s.description = 'A fast and safe Markdown to (X)HTML parser'
|
6
|
-
s.date = '2011-04-
|
6
|
+
s.date = '2011-04-23'
|
7
7
|
s.email = 'vicent@github.com'
|
8
8
|
s.homepage = 'http://github.com/tanoku/redcarpet'
|
9
9
|
s.has_rdoc = true
|
data/test/redcarpet_test.rb
CHANGED
@@ -186,6 +186,18 @@ fenced
|
|
186
186
|
assert Redcarpet.new(text, :fenced_code).to_html =~ /<code/
|
187
187
|
end
|
188
188
|
|
189
|
+
def test_that_gh_blockcode_works
|
190
|
+
text = <<fenced
|
191
|
+
~~~~~ {.python .numbered}
|
192
|
+
This is some unsafe code block
|
193
|
+
with custom CSS classes
|
194
|
+
~~~~~
|
195
|
+
fenced
|
196
|
+
|
197
|
+
assert Redcarpet.new(text, :fenced_code).to_html =~ /<code class/
|
198
|
+
assert Redcarpet.new(text, :fenced_code, :gh_blockcode).to_html !~ /<code class/
|
199
|
+
end
|
200
|
+
|
189
201
|
def test_that_compat_is_working
|
190
202
|
rd = RedcarpetCompat.new(<<EOS)
|
191
203
|
aaa | bbbb
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redcarpet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 11
|
9
|
+
- 0
|
10
|
+
version: 1.11.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Natacha Port\xC3\xA9"
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-04-
|
19
|
+
date: 2011-04-23 00:00:00 +03:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|