RedCloth 4.1.1-x86-mswin32-60 → 4.1.9-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of RedCloth might be problematic. Click here for more details.
- data/CHANGELOG +36 -0
- data/COPYING +1 -1
- data/README +32 -17
- data/Rakefile +1 -0
- data/RedCloth.gemspec +4 -7
- data/ext/redcloth_scan/redcloth.h +53 -22
- data/ext/redcloth_scan/redcloth_attributes.c.rl +2 -3
- data/ext/redcloth_scan/redcloth_attributes.java.rl +5 -6
- data/ext/redcloth_scan/redcloth_attributes.rl +2 -2
- data/ext/redcloth_scan/redcloth_common.rl +5 -1
- data/ext/redcloth_scan/redcloth_inline.c.rl +48 -14
- data/ext/redcloth_scan/redcloth_inline.java.rl +36 -4
- data/ext/redcloth_scan/redcloth_inline.rl +11 -12
- data/ext/redcloth_scan/redcloth_scan.c.rl +12 -14
- data/ext/redcloth_scan/redcloth_scan.java.rl +25 -3
- data/ext/redcloth_scan/redcloth_scan.rl +7 -12
- data/lib/redcloth/formatters/base.rb +26 -20
- data/lib/redcloth/formatters/html.rb +22 -30
- data/lib/redcloth/formatters/latex.rb +45 -17
- data/lib/redcloth/textile_doc.rb +1 -3
- data/lib/redcloth/version.rb +1 -1
- data/lib/redcloth_scan.so +0 -0
- data/test/basic.yml +16 -2
- data/test/code.yml +6 -7
- data/test/html.yml +15 -1
- data/test/images.yml +23 -0
- data/test/links.yml +27 -1
- data/test/lists.yml +19 -1
- data/test/table.yml +73 -4
- data/test/test_custom_tags.rb +13 -1
- data/test/test_erb.rb +1 -1
- data/test/test_extensions.rb +1 -1
- data/test/test_formatters.rb +1 -1
- data/test/test_parser.rb +1 -1
- data/test/test_restrictions.rb +1 -1
- data/test/textism.yml +1 -1
- data/test/threshold.yml +1 -3
- data/test/validate_fixtures.rb +2 -1
- metadata +6 -15
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* redcloth_inline.rl
|
3
3
|
*
|
4
|
-
* Copyright (C)
|
4
|
+
* Copyright (C) 2009 Jason Garber
|
5
5
|
*/
|
6
6
|
import java.io.IOException;
|
7
7
|
|
@@ -53,10 +53,40 @@ public class RedclothInline extends RedclothScanService.Base {
|
|
53
53
|
|
54
54
|
public IRubyObject red_parse_link_attr(IRubyObject self, IRubyObject regs, IRubyObject ref) {
|
55
55
|
IRubyObject txt = ((RubyHash)regs).aref(ref);
|
56
|
-
IRubyObject new_regs = RedclothAttributes.link_attributes(self, txt);
|
56
|
+
IRubyObject new_regs = red_parse_title(RedclothAttributes.link_attributes(self, txt), ref);
|
57
57
|
return regs.callMethod(runtime.getCurrentContext(), "update", new_regs);
|
58
58
|
}
|
59
59
|
|
60
|
+
public IRubyObject red_parse_image_attr(IRubyObject self, IRubyObject regs, IRubyObject ref) {
|
61
|
+
return red_parse_title(regs, ref);
|
62
|
+
}
|
63
|
+
|
64
|
+
public IRubyObject red_parse_title(IRubyObject regs, IRubyObject ref) {
|
65
|
+
IRubyObject name = ((RubyHash)regs).aref(ref);
|
66
|
+
if ( !name.isNil() ) {
|
67
|
+
String s = name.convertToString().toString();
|
68
|
+
int p = s.length();
|
69
|
+
if (s.charAt(p - 1) == ')') {
|
70
|
+
int level = -1;
|
71
|
+
p--;
|
72
|
+
while (p > 0 && level < 0) {
|
73
|
+
switch(s.charAt(p - 1)) {
|
74
|
+
case '(': ++level; break;
|
75
|
+
case ')': --level; break;
|
76
|
+
}
|
77
|
+
--p;
|
78
|
+
}
|
79
|
+
IRubyObject title = runtime.newString(s.substring(p + 1, s.length() - 1));
|
80
|
+
if(p > 0 && s.charAt(p - 1) == ' ') --p;
|
81
|
+
if(p != 0) {
|
82
|
+
((RubyHash)regs).aset(ref, runtime.newString(s.substring(0, p)));
|
83
|
+
((RubyHash)regs).aset(runtime.newSymbol("title"), title);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
return regs;
|
88
|
+
}
|
89
|
+
|
60
90
|
public void PASS_CODE(IRubyObject H, String A, String T, int O) {
|
61
91
|
((RubyString)H).append(red_pass_code(self, regs, runtime.newSymbol(A), T));
|
62
92
|
}
|
@@ -69,8 +99,11 @@ public class RedclothInline extends RedclothScanService.Base {
|
|
69
99
|
red_parse_link_attr(self, regs, runtime.newSymbol(A));
|
70
100
|
}
|
71
101
|
|
102
|
+
public void PARSE_IMAGE_ATTR(String A) {
|
103
|
+
red_parse_image_attr(self, regs, runtime.newSymbol(A));
|
104
|
+
}
|
105
|
+
|
72
106
|
private int opts;
|
73
|
-
private IRubyObject buf;
|
74
107
|
|
75
108
|
public RedclothInline(IRubyObject self, byte[] data, int p, int pe, IRubyObject refs) {
|
76
109
|
this.runtime = self.getRuntime();
|
@@ -90,7 +123,6 @@ public class RedclothInline extends RedclothScanService.Base {
|
|
90
123
|
this.block = RubyString.newEmptyString(runtime);
|
91
124
|
this.regs = runtime.getNil();
|
92
125
|
this.opts = 0;
|
93
|
-
this.buf = runtime.getNil();
|
94
126
|
}
|
95
127
|
|
96
128
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* redcloth_inline.rl
|
3
3
|
*
|
4
|
-
* Copyright (C)
|
4
|
+
* Copyright (C) 2009 Jason Garber
|
5
5
|
*/
|
6
6
|
%%{
|
7
7
|
|
@@ -11,17 +11,18 @@
|
|
11
11
|
mtext_noquotes = mtext -- '"' ;
|
12
12
|
quoted_mtext = '"' mtext_noquotes '"' ;
|
13
13
|
mtext_including_quotes = (mtext_noquotes ' "' mtext_noquotes '" ' mtext_noquotes?)+ ;
|
14
|
-
link_says = ( C_noactions "."* " "* ((quoted_mtext | mtext_including_quotes | mtext_noquotes) -- '":') ) >A %{ STORE("
|
14
|
+
link_says = ( C_noactions "."* " "* ((quoted_mtext | mtext_including_quotes | mtext_noquotes) -- '":') ) >A %{ STORE("name"); } ;
|
15
15
|
link_says_noquotes_noactions = ( C_noquotes_noactions "."* " "* ((mtext_noquotes) -- '":') ) ;
|
16
16
|
link = ( '"' link_says '":' %A uri %{ STORE_URL("href"); } ) >X ;
|
17
17
|
link_noquotes_noactions = ( '"' link_says_noquotes_noactions '":' uri ) ;
|
18
18
|
bracketed_link = ( '["' link_says '":' %A uri %{ STORE("href"); } :> "]" ) >X ;
|
19
19
|
|
20
20
|
# images
|
21
|
-
|
22
|
-
image_is = ( A2 C ". "?
|
21
|
+
image_title = ( '(' mtext ')' ) ;
|
22
|
+
image_is = ( A2 C ". "? (uri image_title?) >A %{ STORE("src"); } ) ;
|
23
23
|
image_link = ( ":" uri >A %{ STORE_URL("href"); } ) ;
|
24
|
-
image = ( "
|
24
|
+
image = ( "!" image_is "!" %A image_link? ) >X ;
|
25
|
+
bracketed_image = ( "[!" image_is "!" %A image_link? "]" ) >X ;
|
25
26
|
|
26
27
|
# footnotes
|
27
28
|
footno = "[" >X %A digit+ %T "]" ;
|
@@ -29,17 +30,14 @@
|
|
29
30
|
# markup
|
30
31
|
end_markup_phrase = (" " | PUNCT | EOF | LF) @{ fhold; };
|
31
32
|
code = "["? "@" >X mtext >A %T :> "@" "]"? ;
|
32
|
-
code_tag_start = "<code" [^>]* ">" ;
|
33
|
-
code_tag_end = "</code>" ;
|
34
33
|
script_tag = ( "<script" [^>]* ">" (default+ -- "</script>") "</script>" LF? ) >X >A %T ;
|
35
|
-
notextile = "<notextile>" >X (default+ -- "</notextile>") >A %T "</notextile>";
|
36
34
|
strong = "["? "*" >X mtext >A %T :> "*" "]"? ;
|
37
35
|
b = "["? "**" >X mtext >A %T :> "**" "]"? ;
|
38
36
|
em = "["? "_" >X mtext >A %T :> "_" "]"? ;
|
39
37
|
i = "["? "__" >X mtext >A %T :> "__" "]"? ;
|
40
38
|
del = "[-" >X C ( mtext ) >A %T :>> "-]" ;
|
41
39
|
emdash_parenthetical_phrase_with_spaces = " -- " mtext " -- " ;
|
42
|
-
del_phrase = (( " " >A %{ STORE("beginning_space"); } "-") >X C ( mtext ) >A %T :>> ( "-" end_markup_phrase )) - emdash_parenthetical_phrase_with_spaces ;
|
40
|
+
del_phrase = (( " " >A %{ STORE("beginning_space"); } "-" | "-" when starts_line) >X C ( mtext ) >A %T :>> ( "-" end_markup_phrase )) - emdash_parenthetical_phrase_with_spaces ;
|
43
41
|
ins = "["? "+" >X mtext >A %T :> "+" "]"? ;
|
44
42
|
sup = "[^" >X mtext >A %T :> "^]" ;
|
45
43
|
sup_phrase = ( "^" when starts_phrase) >X ( mtext ) >A %T :>> ( "^" end_markup_phrase ) ;
|
@@ -97,10 +95,11 @@
|
|
97
95
|
|
98
96
|
main := |*
|
99
97
|
|
100
|
-
image { INLINE(block, "image"); };
|
98
|
+
image { PARSE_IMAGE_ATTR("src"); INLINE(block, "image"); };
|
99
|
+
bracketed_image { PARSE_IMAGE_ATTR("src"); INLINE(block, "image"); };
|
101
100
|
|
102
|
-
link { PARSE_LINK_ATTR("
|
103
|
-
bracketed_link { PARSE_LINK_ATTR("
|
101
|
+
link { PARSE_LINK_ATTR("name"); PASS(block, "name", "link"); };
|
102
|
+
bracketed_link { PARSE_LINK_ATTR("name"); PASS(block, "name", "link"); };
|
104
103
|
|
105
104
|
code { PARSE_ATTR("text"); PASS_CODE(block, "text", "code", opts); };
|
106
105
|
code_tag_start { CAT(block); fgoto code_tag; };
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* redcloth_scan.c.rl
|
3
3
|
*
|
4
|
-
* Copyright (C)
|
4
|
+
* Copyright (C) 2009 Jason Garber
|
5
5
|
*/
|
6
6
|
#define redcloth_scan_c
|
7
7
|
|
@@ -31,11 +31,11 @@ redcloth_transform(self, p, pe, refs)
|
|
31
31
|
VALUE refs;
|
32
32
|
{
|
33
33
|
char *orig_p = p, *orig_pe = pe;
|
34
|
-
int cs, act, nest;
|
34
|
+
int cs, act, nest = 0;
|
35
35
|
char *ts = NULL, *te = NULL, *reg = NULL, *bck = NULL, *eof = NULL;
|
36
|
-
VALUE html =
|
37
|
-
VALUE table =
|
38
|
-
VALUE block =
|
36
|
+
VALUE html = STR_NEW2("");
|
37
|
+
VALUE table = STR_NEW2("");
|
38
|
+
VALUE block = STR_NEW2("");
|
39
39
|
VALUE regs; CLEAR_REGS()
|
40
40
|
|
41
41
|
|
@@ -84,7 +84,7 @@ redcloth_html_esc(int argc, VALUE* argv, VALUE self) //(self, str, level)
|
|
84
84
|
|
85
85
|
rb_scan_args(argc, argv, "11", &str, &level);
|
86
86
|
|
87
|
-
VALUE new_str =
|
87
|
+
VALUE new_str = STR_NEW2("");
|
88
88
|
if (str == Qnil)
|
89
89
|
return new_str;
|
90
90
|
|
@@ -95,7 +95,7 @@ redcloth_html_esc(int argc, VALUE* argv, VALUE self) //(self, str, level)
|
|
95
95
|
|
96
96
|
char *ts = RSTRING_PTR(str), *te = RSTRING_PTR(str) + RSTRING_LEN(str);
|
97
97
|
char *t = ts, *t2 = ts, *ch = NULL;
|
98
|
-
if (te <= ts) return;
|
98
|
+
if (te <= ts) return Qnil;
|
99
99
|
|
100
100
|
while (t2 < te) {
|
101
101
|
ch = NULL;
|
@@ -142,7 +142,7 @@ redcloth_html_esc(int argc, VALUE* argv, VALUE self) //(self, str, level)
|
|
142
142
|
static VALUE
|
143
143
|
redcloth_latex_esc(VALUE self, VALUE str)
|
144
144
|
{
|
145
|
-
VALUE new_str =
|
145
|
+
VALUE new_str = STR_NEW2("");
|
146
146
|
|
147
147
|
if (str == Qnil)
|
148
148
|
return new_str;
|
@@ -154,7 +154,7 @@ redcloth_latex_esc(VALUE self, VALUE str)
|
|
154
154
|
|
155
155
|
char *ts = RSTRING_PTR(str), *te = RSTRING_PTR(str) + RSTRING_LEN(str);
|
156
156
|
char *t = ts, *t2 = ts, *ch = NULL;
|
157
|
-
if (te <= ts) return;
|
157
|
+
if (te <= ts) return Qnil;
|
158
158
|
|
159
159
|
while (t2 < te) {
|
160
160
|
ch = NULL;
|
@@ -181,7 +181,7 @@ redcloth_latex_esc(VALUE self, VALUE str)
|
|
181
181
|
if (t2 > t)
|
182
182
|
rb_str_cat(new_str, t, t2-t);
|
183
183
|
VALUE opts = rb_hash_new();
|
184
|
-
rb_hash_aset(opts, ID2SYM(rb_intern("text")),
|
184
|
+
rb_hash_aset(opts, ID2SYM(rb_intern("text")), STR_NEW2(ch));
|
185
185
|
rb_str_concat(new_str, rb_funcall(self, rb_intern("entity"), 1, opts));
|
186
186
|
t = t2 + 1;
|
187
187
|
}
|
@@ -201,12 +201,10 @@ static VALUE
|
|
201
201
|
redcloth_to(self, formatter)
|
202
202
|
VALUE self, formatter;
|
203
203
|
{
|
204
|
-
|
205
|
-
int len = 0;
|
206
|
-
|
207
|
-
rb_funcall(self, rb_intern("delete!"), 1, rb_str_new2("\r"));
|
204
|
+
rb_funcall(self, rb_intern("delete!"), 1, STR_NEW2("\r"));
|
208
205
|
VALUE working_copy = rb_obj_clone(self);
|
209
206
|
rb_extend_object(working_copy, formatter);
|
207
|
+
|
210
208
|
if (rb_funcall(working_copy, rb_intern("lite_mode"), 0) == Qtrue) {
|
211
209
|
return redcloth_inline2(working_copy, self, rb_hash_new());
|
212
210
|
} else {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* redcloth_scan.java.rl
|
3
3
|
*
|
4
|
-
* Copyright (C)
|
4
|
+
* Copyright (C) 2009 Jason Garber
|
5
5
|
*/
|
6
6
|
import java.io.IOException;
|
7
7
|
|
@@ -108,8 +108,20 @@ public class RedclothScanService implements BasicLibraryService {
|
|
108
108
|
boolean punct = true;
|
109
109
|
while(p > reg && punct) {
|
110
110
|
switch(data[p - 1]) {
|
111
|
+
case ')':
|
112
|
+
int tempP = p - 1;
|
113
|
+
int level = -1;
|
114
|
+
while(tempP > reg) {
|
115
|
+
switch(data[tempP - 1]) {
|
116
|
+
case '(': ++level; break;
|
117
|
+
case ')': --level; break;
|
118
|
+
}
|
119
|
+
--tempP;
|
120
|
+
}
|
121
|
+
if (level == 0) { punct = false; } else { --p; }
|
122
|
+
break;
|
111
123
|
case '!': case '"': case '#': case '$': case '%': case ']': case '[': case '&': case '\'':
|
112
|
-
case '*': case '+': case ',': case '-': case '.': case '
|
124
|
+
case '*': case '+': case ',': case '-': case '.': case '(': case ':':
|
113
125
|
case ';': case '=': case '?': case '@': case '\\': case '^': case '_':
|
114
126
|
case '`': case '|': case '~': p--; break;
|
115
127
|
default: punct = false;
|
@@ -160,7 +172,8 @@ public class RedclothScanService implements BasicLibraryService {
|
|
160
172
|
((RubyHash)regs).aset(sym_text, inline2(self, block, refs));
|
161
173
|
}
|
162
174
|
|
163
|
-
|
175
|
+
IRubyObject formatterMethods = ((RubyObject)self).callMethod(runtime.getCurrentContext(), "formatter_methods");
|
176
|
+
if( ((RubyArray)formatterMethods).includes(runtime.getCurrentContext(), method) ) {
|
164
177
|
block = self.callMethod(runtime.getCurrentContext(), method.asJavaString(), regs);
|
165
178
|
} else {
|
166
179
|
IRubyObject fallback = ((RubyHash)regs).aref(runtime.newSymbol("fallback"));
|
@@ -229,6 +242,10 @@ public class RedclothScanService implements BasicLibraryService {
|
|
229
242
|
((RubyString)H).append(self.callMethod(runtime.getCurrentContext(), T, regs));
|
230
243
|
}
|
231
244
|
|
245
|
+
public void RSTRIP_BANG(IRubyObject H) {
|
246
|
+
((RubyString)H).callMethod(runtime.getCurrentContext(), "rstrip!");
|
247
|
+
}
|
248
|
+
|
232
249
|
public void DONE(IRubyObject H) {
|
233
250
|
((RubyString)html).append(H);
|
234
251
|
CLEAR(H);
|
@@ -403,6 +420,11 @@ public class RedclothScanService implements BasicLibraryService {
|
|
403
420
|
|
404
421
|
((RubyObject)workingCopy).extend(new IRubyObject[]{formatter});
|
405
422
|
|
423
|
+
IRubyObject workingCopyMethods = workingCopy.callMethod(runtime.getCurrentContext(), "methods");
|
424
|
+
IRubyObject classInstanceMethods = workingCopy.getType().callMethod(runtime.getCurrentContext(), "instance_methods");
|
425
|
+
IRubyObject customTags = workingCopyMethods.callMethod(runtime.getCurrentContext(), "-", classInstanceMethods);
|
426
|
+
((RubyObject)workingCopy).setInstanceVariable("@custom_tags", customTags);
|
427
|
+
|
406
428
|
if(workingCopy.callMethod(runtime.getCurrentContext(), "lite_mode").isTrue()) {
|
407
429
|
return inline2(workingCopy, self, RubyHash.newHash(runtime));
|
408
430
|
} else {
|
@@ -1,19 +1,18 @@
|
|
1
1
|
/*
|
2
2
|
* redcloth_scan.rl
|
3
3
|
*
|
4
|
-
* Copyright (C)
|
4
|
+
* Copyright (C) 2009 Jason Garber
|
5
5
|
*/
|
6
6
|
%%{
|
7
7
|
|
8
8
|
machine redcloth_scan;
|
9
9
|
|
10
10
|
# blocks
|
11
|
-
|
12
|
-
notextile_tag_end = "</notextile>" LF? ;
|
11
|
+
notextile_tag = notextile (LF | EOF) ;
|
13
12
|
noparagraph_line_start = " "+ ;
|
14
13
|
notextile_block_start = ( "notextile" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
|
15
|
-
pre_tag_start = "<pre" [^>]* ">" (space*
|
16
|
-
pre_tag_end = (
|
14
|
+
pre_tag_start = "<pre" [^>]* ">" (space* code_tag_start)? ;
|
15
|
+
pre_tag_end = (code_tag_end space*)? "</pre>" LF? ;
|
17
16
|
pre_block_start = ( "pre" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
|
18
17
|
bc_start = ( "bc" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
|
19
18
|
bq_start = ( "bq" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) ( ":" %A uri %{ STORE("cite"); } )? " "+ ) ;
|
@@ -30,7 +29,7 @@
|
|
30
29
|
ol = "#" %{nest++; list_type = "ol";};
|
31
30
|
ul_start = ( ul | ol )* ul A C :> " "+ ;
|
32
31
|
ol_start = ( ul | ol )* ol N A C :> " "+ ;
|
33
|
-
list_start = ( ul_start | ol_start ) >{nest = 0;} ;
|
32
|
+
list_start = " "* ( ul_start | ol_start ) >{nest = 0;} ;
|
34
33
|
dt_start = "-" . " "+ ;
|
35
34
|
dd_start = ":=" ;
|
36
35
|
long_dd = dd_start " "* LF %{ ADD_BLOCK(); ASET("type", "dd"); } any+ >A %{ TRANSFORM("text"); } :>> "=:" ;
|
@@ -109,11 +108,6 @@
|
|
109
108
|
LF { ADD_BLOCK(); fgoto main; };
|
110
109
|
default => cat;
|
111
110
|
*|;
|
112
|
-
|
113
|
-
notextile_tag := |*
|
114
|
-
notextile_tag_end { ADD_BLOCK(); fgoto main; };
|
115
|
-
default => cat;
|
116
|
-
*|;
|
117
111
|
|
118
112
|
notextile_block := |*
|
119
113
|
EOF {
|
@@ -178,6 +172,7 @@
|
|
178
172
|
} else {
|
179
173
|
ADD_EXTENDED_BLOCKCODE();
|
180
174
|
CAT(html);
|
175
|
+
RSTRIP_BANG(html);
|
181
176
|
INLINE(html, "bc_close");
|
182
177
|
SET_PLAIN_BLOCK("p");
|
183
178
|
END_EXTENDED();
|
@@ -293,7 +288,7 @@
|
|
293
288
|
|
294
289
|
main := |*
|
295
290
|
noparagraph_line_start { ASET("type", "ignored_line"); fgoto noparagraph_line; };
|
296
|
-
|
291
|
+
notextile_tag { INLINE(block, "notextile"); };
|
297
292
|
notextile_block_start { ASET("type", "notextile"); fgoto notextile_block; };
|
298
293
|
script_tag_start { CAT(block); fgoto script_tag; };
|
299
294
|
pre_tag_start { ASET("type", "notextile"); CAT(block); fgoto pre_tag; };
|
@@ -1,26 +1,6 @@
|
|
1
1
|
module RedCloth::Formatters
|
2
2
|
module Base
|
3
3
|
|
4
|
-
def pba(opts)
|
5
|
-
opts.delete(:style) if filter_styles
|
6
|
-
opts.delete(:class) if filter_classes
|
7
|
-
opts.delete(:id) if filter_ids
|
8
|
-
|
9
|
-
atts = ''
|
10
|
-
opts[:"text-align"] = opts.delete(:align)
|
11
|
-
opts[:style] += ';' if opts[:style] && (opts[:style][-1..-1] != ';')
|
12
|
-
[:float, :"text-align", :"vertical-align"].each do |a|
|
13
|
-
opts[:style] = "#{a}:#{opts[a]};#{opts[:style]}" if opts[a]
|
14
|
-
end
|
15
|
-
[:"padding-right", :"padding-left"].each do |a|
|
16
|
-
opts[:style] = "#{a}:#{opts[a]}em;#{opts[:style]}" if opts[a]
|
17
|
-
end
|
18
|
-
[:style, :class, :lang, :id, :colspan, :rowspan, :title, :start, :align].each do |a|
|
19
|
-
atts << " #{a}=\"#{ html_esc(opts[a].to_s, :html_escape_attributes) }\"" if opts[a]
|
20
|
-
end
|
21
|
-
atts
|
22
|
-
end
|
23
|
-
|
24
4
|
def ignore(opts)
|
25
5
|
opts[:text]
|
26
6
|
end
|
@@ -41,6 +21,28 @@ module RedCloth::Formatters
|
|
41
21
|
end
|
42
22
|
end
|
43
23
|
|
24
|
+
private
|
25
|
+
|
26
|
+
def pba(opts)
|
27
|
+
opts.delete(:style) if filter_styles
|
28
|
+
opts.delete(:class) if filter_classes
|
29
|
+
opts.delete(:id) if filter_ids
|
30
|
+
|
31
|
+
atts = ''
|
32
|
+
opts[:"text-align"] = opts.delete(:align)
|
33
|
+
opts[:style] += ';' if opts[:style] && (opts[:style][-1..-1] != ';')
|
34
|
+
[:float, :"text-align", :"vertical-align"].each do |a|
|
35
|
+
opts[:style] = "#{a}:#{opts[a]};#{opts[:style]}" if opts[a]
|
36
|
+
end
|
37
|
+
[:"padding-right", :"padding-left"].each do |a|
|
38
|
+
opts[:style] = "#{a}:#{opts[a]}em;#{opts[:style]}" if opts[a]
|
39
|
+
end
|
40
|
+
[:style, :class, :lang, :id, :colspan, :rowspan, :title, :start, :align].each do |a|
|
41
|
+
atts << " #{a}=\"#{ html_esc(opts[a].to_s, :html_escape_attributes) }\"" if opts[a]
|
42
|
+
end
|
43
|
+
atts
|
44
|
+
end
|
45
|
+
|
44
46
|
def method_missing(method, opts)
|
45
47
|
opts[:text] || ""
|
46
48
|
end
|
@@ -52,6 +54,10 @@ module RedCloth::Formatters
|
|
52
54
|
def after_transform(text)
|
53
55
|
|
54
56
|
end
|
57
|
+
|
58
|
+
def formatter_methods
|
59
|
+
singleton_methods.map! {|method| method.to_sym }
|
60
|
+
end
|
55
61
|
|
56
62
|
end
|
57
63
|
end
|
@@ -1,25 +1,6 @@
|
|
1
1
|
module RedCloth::Formatters::HTML
|
2
2
|
include RedCloth::Formatters::Base
|
3
3
|
|
4
|
-
# escapement for regular HTML (not in PRE tag)
|
5
|
-
def escape(text)
|
6
|
-
html_esc(text)
|
7
|
-
end
|
8
|
-
|
9
|
-
# escapement for HTML in a PRE tag
|
10
|
-
def escape_pre(text)
|
11
|
-
html_esc(text, :html_escape_preformatted)
|
12
|
-
end
|
13
|
-
|
14
|
-
# escaping for HTML attributes
|
15
|
-
def escape_attribute(text)
|
16
|
-
html_esc(text, :html_escape_attributes)
|
17
|
-
end
|
18
|
-
|
19
|
-
def after_transform(text)
|
20
|
-
text.chomp!
|
21
|
-
end
|
22
|
-
|
23
4
|
[:h1, :h2, :h3, :h4, :h5, :h6, :p, :pre, :div].each do |m|
|
24
5
|
define_method(m) do |opts|
|
25
6
|
"<#{m}#{pba(opts)}>#{opts[:text]}</#{m}>\n"
|
@@ -129,18 +110,7 @@ module RedCloth::Formatters::HTML
|
|
129
110
|
"</blockquote>\n"
|
130
111
|
end
|
131
112
|
|
132
|
-
LINK_TEXT_WITH_TITLE_RE = /
|
133
|
-
([^"]+?) # $text
|
134
|
-
\s?
|
135
|
-
\(([^)]+?)\) # $title
|
136
|
-
$
|
137
|
-
/x
|
138
113
|
def link(opts)
|
139
|
-
if opts[:name] =~ LINK_TEXT_WITH_TITLE_RE
|
140
|
-
md = LINK_TEXT_WITH_TITLE_RE.match(opts[:name])
|
141
|
-
opts[:name] = md[1]
|
142
|
-
opts[:title] = md[2]
|
143
|
-
end
|
144
114
|
"<a href=\"#{escape_attribute opts[:href]}\"#{pba(opts)}>#{opts[:name]}</a>"
|
145
115
|
end
|
146
116
|
|
@@ -281,6 +251,28 @@ module RedCloth::Formatters::HTML
|
|
281
251
|
opts[:text] + "\n"
|
282
252
|
end
|
283
253
|
|
254
|
+
private
|
255
|
+
|
256
|
+
# escapement for regular HTML (not in PRE tag)
|
257
|
+
def escape(text)
|
258
|
+
html_esc(text)
|
259
|
+
end
|
260
|
+
|
261
|
+
# escapement for HTML in a PRE tag
|
262
|
+
def escape_pre(text)
|
263
|
+
html_esc(text, :html_escape_preformatted)
|
264
|
+
end
|
265
|
+
|
266
|
+
# escaping for HTML attributes
|
267
|
+
def escape_attribute(text)
|
268
|
+
html_esc(text, :html_escape_attributes)
|
269
|
+
end
|
270
|
+
|
271
|
+
def after_transform(text)
|
272
|
+
text.chomp!
|
273
|
+
end
|
274
|
+
|
275
|
+
|
284
276
|
def before_transform(text)
|
285
277
|
clean_html(text) if sanitize_html
|
286
278
|
end
|