RedCloth 4.1.9-universal-java → 4.2.0-universal-java

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.

Files changed (68) hide show
  1. data/CHANGELOG +55 -0
  2. data/Manifest +34 -38
  3. data/README +17 -5
  4. data/Rakefile +79 -30
  5. data/RedCloth.gemspec +8 -9
  6. data/ext/redcloth_scan/redcloth.h +38 -13
  7. data/lib/redcloth.rb +9 -3
  8. data/lib/redcloth/formatters/html.rb +2 -2
  9. data/lib/redcloth/formatters/latex.rb +99 -54
  10. data/lib/redcloth/formatters/latex_entities.yml +2 -2
  11. data/lib/redcloth/version.rb +9 -4
  12. data/lib/redcloth_scan.jar +0 -0
  13. data/lib/tasks/pureruby.rake +12 -0
  14. data/spec/custom_tags_spec.rb +50 -0
  15. data/spec/differs/inline.rb +48 -0
  16. data/{test/test_erb.rb → spec/erb_spec.rb} +6 -9
  17. data/spec/extension_spec.rb +26 -0
  18. data/{test → spec/fixtures}/basic.yml +90 -4
  19. data/{test → spec/fixtures}/code.yml +29 -0
  20. data/{test → spec/fixtures}/definitions.yml +0 -0
  21. data/{test → spec/fixtures}/extra_whitespace.yml +0 -0
  22. data/{test → spec/fixtures}/filter_html.yml +0 -0
  23. data/{test → spec/fixtures}/filter_pba.yml +0 -0
  24. data/{test → spec/fixtures}/html.yml +15 -0
  25. data/{test → spec/fixtures}/images.yml +16 -6
  26. data/{test → spec/fixtures}/instiki.yml +0 -0
  27. data/{test → spec/fixtures}/links.yml +7 -1
  28. data/{test → spec/fixtures}/lists.yml +162 -1
  29. data/{test → spec/fixtures}/poignant.yml +0 -0
  30. data/{test → spec/fixtures}/sanitize_html.yml +0 -0
  31. data/{test → spec/fixtures}/table.yml +121 -23
  32. data/{test → spec/fixtures}/textism.yml +44 -15
  33. data/{test → spec/fixtures}/threshold.yml +6 -14
  34. data/spec/formatters/class_filtered_html_spec.rb +7 -0
  35. data/spec/formatters/filtered_html_spec.rb +7 -0
  36. data/spec/formatters/html_no_breaks_spec.rb +9 -0
  37. data/spec/formatters/html_spec.rb +13 -0
  38. data/spec/formatters/id_filtered_html_spec.rb +7 -0
  39. data/spec/formatters/latex_spec.rb +13 -0
  40. data/spec/formatters/lite_mode_html_spec.rb +7 -0
  41. data/spec/formatters/no_span_caps_html_spec.rb +7 -0
  42. data/spec/formatters/sanitized_html_spec.rb +7 -0
  43. data/spec/formatters/style_filtered_html_spec.rb +7 -0
  44. data/spec/parser_spec.rb +95 -0
  45. data/spec/spec.opts +3 -0
  46. data/spec/spec_helper.rb +42 -0
  47. metadata +46 -51
  48. data/ext/mingw-rbconfig.rb +0 -176
  49. data/ext/redcloth_scan/redcloth_attributes.c.rl +0 -55
  50. data/ext/redcloth_scan/redcloth_attributes.java.rl +0 -95
  51. data/ext/redcloth_scan/redcloth_attributes.rl +0 -33
  52. data/ext/redcloth_scan/redcloth_common.c.rl +0 -18
  53. data/ext/redcloth_scan/redcloth_common.java.rl +0 -18
  54. data/ext/redcloth_scan/redcloth_common.rl +0 -115
  55. data/ext/redcloth_scan/redcloth_inline.c.rl +0 -193
  56. data/ext/redcloth_scan/redcloth_inline.java.rl +0 -140
  57. data/ext/redcloth_scan/redcloth_inline.rl +0 -156
  58. data/ext/redcloth_scan/redcloth_scan.c.rl +0 -228
  59. data/ext/redcloth_scan/redcloth_scan.java.rl +0 -577
  60. data/ext/redcloth_scan/redcloth_scan.rl +0 -320
  61. data/extras/ragel_profiler.rb +0 -73
  62. data/test/helper.rb +0 -108
  63. data/test/test_custom_tags.rb +0 -58
  64. data/test/test_extensions.rb +0 -31
  65. data/test/test_formatters.rb +0 -24
  66. data/test/test_parser.rb +0 -73
  67. data/test/test_restrictions.rb +0 -41
  68. data/test/validate_fixtures.rb +0 -74
@@ -1,55 +0,0 @@
1
- /*
2
- * redcloth_attributes.c.rl
3
- *
4
- * Copyright (C) 2009 Jason Garber
5
- */
6
- #include <ruby.h>
7
- #include "redcloth.h"
8
-
9
- %%{
10
-
11
- machine redcloth_attributes;
12
- include redcloth_common "redcloth_common.c.rl";
13
- include redcloth_attributes "redcloth_attributes.rl";
14
-
15
- }%%
16
-
17
- %% write data nofinal;
18
-
19
-
20
- VALUE
21
- redcloth_attribute_parser(machine, self, p, pe)
22
- int machine;
23
- VALUE self;
24
- char *p, *pe;
25
- {
26
- int cs, act;
27
- char *ts = 0, *te = 0, *reg = 0, *bck = NULL, *eof = NULL;
28
- VALUE regs = rb_hash_new();
29
-
30
- %% write init;
31
-
32
- cs = machine;
33
-
34
- %% write exec;
35
-
36
- return regs;
37
- }
38
-
39
- VALUE
40
- redcloth_attributes(self, str)
41
- VALUE self, str;
42
- {
43
- StringValue(str);
44
- int cs = redcloth_attributes_en_inline;
45
- return redcloth_attribute_parser(cs, self, RSTRING_PTR(str), RSTRING_PTR(str) + RSTRING_LEN(str) + 1);
46
- }
47
-
48
- VALUE
49
- redcloth_link_attributes(self, str)
50
- VALUE self, str;
51
- {
52
- StringValue(str);
53
- int cs = redcloth_attributes_en_link_says;
54
- return redcloth_attribute_parser(cs, self, RSTRING_PTR(str), RSTRING_PTR(str) + RSTRING_LEN(str) + 1);
55
- }
@@ -1,95 +0,0 @@
1
- /*
2
- * redcloth_attributes.rl
3
- *
4
- * Copyright (C) 2009 Jason Garber
5
- */
6
- import java.io.IOException;
7
-
8
- import org.jruby.Ruby;
9
- import org.jruby.RubyArray;
10
- import org.jruby.RubyClass;
11
- import org.jruby.RubyHash;
12
- import org.jruby.RubyModule;
13
- import org.jruby.RubyNumeric;
14
- import org.jruby.RubyObject;
15
- import org.jruby.RubyString;
16
- import org.jruby.RubySymbol;
17
- import org.jruby.anno.JRubyMethod;
18
- import org.jruby.runtime.Block;
19
- import org.jruby.runtime.CallbackFactory;
20
- import org.jruby.runtime.builtin.IRubyObject;
21
- import org.jruby.exceptions.RaiseException;
22
- import org.jruby.runtime.load.BasicLibraryService;
23
-
24
- import org.jruby.util.ByteList;
25
-
26
- public class RedclothAttributes extends RedclothScanService.Base {
27
-
28
- %%{
29
-
30
- machine redcloth_attributes;
31
- include redcloth_common "redcloth_common.java.rl";
32
- include redcloth_attributes "redcloth_attributes.rl";
33
-
34
- }%%
35
-
36
- %% write data nofinal;
37
-
38
- public void SET_ATTRIBUTES() {
39
- SET_ATTRIBUTE("class_buf", "class");
40
- SET_ATTRIBUTE("id_buf", "id");
41
- SET_ATTRIBUTE("lang_buf", "lang");
42
- SET_ATTRIBUTE("style_buf", "style");
43
- }
44
-
45
- public void SET_ATTRIBUTE(String B, String A) {
46
- if(!((RubyHash)regs).aref(runtime.newSymbol(B)).isNil()) {
47
- ((RubyHash)regs).aset(runtime.newSymbol(A), ((RubyHash)regs).aref(runtime.newSymbol(B)));
48
- }
49
- }
50
-
51
- private int machine;
52
-
53
- public RedclothAttributes(int machine, IRubyObject self, byte[] data, int p, int pe) {
54
- this.runtime = self.getRuntime();
55
- this.self = self;
56
-
57
- // This is GROSS but necessary for EOF matching
58
- this.data = new byte[pe+1];
59
- System.arraycopy(data, p, this.data, 0, pe);
60
- this.data[pe] = 0;
61
-
62
- this.p = 0;
63
- this.pe = pe+1;
64
- this.eof = this.pe;
65
- this.orig_p = 0;
66
- this.orig_pe = this.pe;
67
-
68
- this.regs = RubyHash.newHash(runtime);
69
- this.machine = machine;
70
- }
71
-
72
- public IRubyObject parse() {
73
- %% write init;
74
-
75
- cs = machine;
76
-
77
- %% write exec;
78
-
79
- return regs;
80
- }
81
-
82
- public static IRubyObject attributes(IRubyObject self, IRubyObject str) {
83
- ByteList bl = str.convertToString().getByteList();
84
- int cs = redcloth_attributes_en_inline;
85
- return new RedclothAttributes(cs, self, bl.bytes, bl.begin, bl.realSize).parse();
86
- }
87
-
88
- public static IRubyObject link_attributes(IRubyObject self, IRubyObject str) {
89
- Ruby runtime = self.getRuntime();
90
-
91
- ByteList bl = str.convertToString().getByteList();
92
- int cs = redcloth_attributes_en_link_says;
93
- return new RedclothAttributes(cs, self, bl.bytes, bl.begin, bl.realSize).parse();
94
- }
95
- }
@@ -1,33 +0,0 @@
1
- /*
2
- * redcloth_attributes.rl
3
- *
4
- * Copyright (C) 2009 Jason Garber
5
- */
6
- %%{
7
-
8
- machine redcloth_attributes;
9
-
10
- C2_CLAS = ( "(" ( [^)#]+ >A %{ STORE("class_buf"); } )? ("#" [^)]+ >A %{STORE("id_buf");} )? ")" ) ;
11
- C2_LNGE = ( "[" [^\[\]]+ >A %{ STORE("lang_buf"); } "]" ) ;
12
- C2_STYL = ( "{" [^}]+ >A %{ STORE("style_buf"); } "}" ) ;
13
- C2 = ( C2_CLAS | C2_STYL | C2_LNGE )+ ;
14
-
15
- mtext_with_attributes = ( C2 mtext >A %T ) >X ;
16
-
17
- inline := |*
18
-
19
- mtext_with_attributes { SET_ATTRIBUTES(); } ;
20
-
21
- *|;
22
-
23
- link_text_with_attributes = C2 "."* " "* ( mtext+ ) >A %{ STORE("name"); } ;
24
- link_text_without_attributes = ( mtext+ ) >B %{ STORE_B("name_without_attributes"); } ;
25
-
26
- link_says := |*
27
-
28
- link_text_with_attributes { SET_ATTRIBUTES(); } ;
29
- link_text_without_attributes { SET_ATTRIBUTE("name_without_attributes", "name"); } ;
30
-
31
- *|;
32
-
33
- }%%;
@@ -1,18 +0,0 @@
1
- %%{
2
-
3
- machine redcloth_common;
4
- include redcloth_common "redcloth_common.rl";
5
-
6
- action esc { rb_str_cat_escaped(self, block, ts, te); }
7
- action esc_pre { rb_str_cat_escaped_for_preformatted(self, block, ts, te); }
8
- action ignore { rb_str_append(block, rb_funcall(self, rb_intern("ignore"), 1, regs)); }
9
-
10
- # conditionals
11
- action starts_line {
12
- p == orig_p || *(p-1) == '\r' || *(p-1) == '\n' || *(p-1) == '\f'
13
- }
14
- action starts_phrase {
15
- p == orig_p || *(p-1) == '\r' || *(p-1) == '\n' || *(p-1) == '\f' || *(p-1) == ' '
16
- }
17
-
18
- }%%;
@@ -1,18 +0,0 @@
1
- %%{
2
-
3
- machine redcloth_common;
4
- include redcloth_common "redcloth_common.rl";
5
-
6
- action esc { strCatEscaped(self, block, data, ts, te); }
7
- action esc_pre { strCatEscapedForPreformatted(self, block, data, ts, te); }
8
- action ignore { ((RubyString)block).append(self.callMethod(runtime.getCurrentContext(), "ignore", regs)); }
9
-
10
- # conditionals
11
- action starts_line {
12
- p == orig_p || data[(p-1)] == '\r' || data[(p-1)] == '\n' || data[(p-1)] == '\f'
13
- }
14
- action starts_phrase {
15
- p == orig_p || data[(p-1)] == '\r' || data[(p-1)] == '\n' || data[(p-1)] == '\f' || data[(p-1)] == ' '
16
- }
17
-
18
- }%%;
@@ -1,115 +0,0 @@
1
- %%{
2
-
3
- machine redcloth_common;
4
-
5
- action A { reg = p; }
6
- action B { bck = p; }
7
- action T { STORE("text"); }
8
- action X { CLEAR_REGS(); RESET_REG(); }
9
- action cat { CAT(block); }
10
-
11
- # simple
12
- LF = ( '\n' ) ;
13
- default = ^0 ;
14
- EOF = 0 ;
15
-
16
- # textile modifiers
17
- A_LEFT = "<" %{ ASET("align", "left"); } ;
18
- A_RIGHT = ">" %{ ASET("align", "right"); } ;
19
- A_JUSTIFIED = "<>" %{ ASET("align", "justify"); } ;
20
- A_CENTER = "=" %{ ASET("align", "center"); } ;
21
- A_PADLEFT = "(" >A %{ AINC("padding-left"); } ;
22
- A_PADRIGHT = ")" >A %{ AINC("padding-right"); } ;
23
- A_HLGN = ( A_LEFT | A_RIGHT | A_JUSTIFIED | A_CENTER | A_PADLEFT | A_PADRIGHT ) ;
24
- A_LIMIT = ( A_LEFT | A_CENTER | A_RIGHT ) ;
25
- A_VLGN = ( "-" %{ ASET("vertical-align", "middle"); } | "^" %{ ASET("vertical-align", "top"); } | "~" %{ ASET("vertical-align", "bottom"); } ) ;
26
- C_CLAS = ( "(" ( [^)#]+ >A %{ STORE("class"); } )? ("#" [^)]+ >A %{STORE("id");} )? ")" ) ;
27
- C_LNGE = ( "[" [^\]]+ >A %{ STORE("lang"); } "]" ) ;
28
- C_STYL = ( "{" [^}]+ >A %{ STORE("style"); } "}" ) ;
29
- S_CSPN = ( "\\" [0-9]+ >A %{ STORE("colspan"); } ) ;
30
- S_RSPN = ( "/" [0-9]+ >A %{ STORE("rowspan"); } ) ;
31
- D_HEADER = "_" %{ ASET("th", "true"); } ;
32
- A = ( ( A_HLGN | A_VLGN )* ) ;
33
- A2 = ( A_LIMIT? ) ;
34
- S = ( S_CSPN | S_RSPN )* ;
35
- C = ( C_CLAS | C_STYL | C_LNGE )* ;
36
- D = ( D_HEADER ) ;
37
- N_CONT = "_" %{ list_continue = 1; };
38
- N_NUM = digit+ >A %{ STORE("start"); };
39
- N = ( N_CONT | N_NUM )? ;
40
- PUNCT = ( "!" | '"' | "#" | "$" | "%" | "&" | "'" | "," | "-" | "." | "/" | ":" | ";" | "=" | "?" | "\\" | "^" | "`" | "|" | "~" | "[" | "]" | "(" | ")" | "<" ) ;
41
- dotspace = ("." " "*) ;
42
- indent = [ \t]* ;
43
-
44
- # very un-DRY; Adrian says an action-stripping macro will come in a future Ragel version
45
- A_LEFT_noactions = "<" ;
46
- A_RIGHT_noactions = ">" ;
47
- A_JUSTIFIED_noactions = "<>" ;
48
- A_CENTER_noactions = "=" ;
49
- A_PADLEFT_noactions = "(" ;
50
- A_PADRIGHT_noactions = ")" ;
51
- A_HLGN_noactions = ( A_LEFT_noactions | A_RIGHT_noactions | A_JUSTIFIED_noactions | A_CENTER_noactions | A_PADLEFT_noactions | A_PADRIGHT_noactions ) ;
52
- A_VLGN_noactions = ( "-" | "^" | "~" ) ;
53
- C_CLAS_noactions = ( "(" ( [^)#]+ )? ("#" [^)]+ )? ")" ) ;
54
- C_LNGE_noactions = ( "[" [^\]]+ "]" ) ;
55
- C_STYL_noactions = ( "{" [^}]+ "}" ) ;
56
- A_noactions = ( ( A_HLGN_noactions | A_VLGN_noactions )* ) ;
57
- C_noactions = ( C_CLAS_noactions | C_STYL_noactions | C_LNGE_noactions )* ;
58
- C_noquotes_noactions = C_noactions -- '"' ;
59
-
60
- # text blocks
61
- trailing = PUNCT - ("'" | '"') ;
62
- chars = (default - space)+ ;
63
- phrase = chars -- trailing ;
64
-
65
- # html tags (from Hpricot)
66
- NameChar = [\-A-Za-z0-9._:?] ;
67
- Name = [A-Za-z_:] NameChar* ;
68
- NameAttr = NameChar+ ;
69
- Q1Attr = [^']* ;
70
- Q2Attr = [^"]* ;
71
- UnqAttr = ( space | [^ \t\r\n<>"'] [^ \t\r\n<>]* ) ;
72
- Nmtoken = NameChar+ ;
73
- Attr = NameAttr space* "=" space* ('"' Q2Attr '"' | "'" Q1Attr "'" | UnqAttr space+ ) space* ;
74
- AttrEnd = ( NameAttr space* "=" space* UnqAttr? | Nmtoken ) ;
75
- AttrSet = ( Attr | Nmtoken space+ ) ;
76
-
77
- script_tag_start = ( "<script" [^>]* ">" ) >X >A %T ;
78
- script_tag_end = ( "</script>" >A %T LF? ) >X ;
79
-
80
- code_tag_start = "<code" [^>]* ">" ;
81
- code_tag_end = "</code>" ;
82
-
83
- notextile = "<notextile>" >X (default+ -- "</notextile>") >A %T "</notextile>";
84
-
85
- # URI tokens (lifted from Mongrel)
86
- CTL = (cntrl | 127);
87
- safe = ("$" | "-" | "_" | ".");
88
- extra = ("!" | "*" | "'" | "(" | ")" | "," | "#");
89
- reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
90
- unsafe = (CTL | " " | "\"" | "%" | "<" | ">");
91
- national = any -- (alpha | digit | reserved | extra | safe | unsafe);
92
- unreserved = (alpha | digit | safe | extra | national);
93
- escape = ("%" xdigit xdigit);
94
- uchar = (unreserved | escape);
95
- pchar = (uchar | ":" | "@" | "&" | "=" | "+");
96
- scheme = ( alpha | digit | "+" | "-" | "." )+ ;
97
- absolute_uri = (scheme ":" (uchar | reserved )*);
98
- safepath = (pchar* (alpha | digit | safe) pchar*) ;
99
- path = (safepath ( "/" pchar* )*) ;
100
- query = ( uchar | reserved )* ;
101
- param = ( pchar | "/" )* ;
102
- params = (param ( ";" param )*) ;
103
- rel_path = (path (";" params)?) ("?" query)?;
104
- absolute_path = ("/"+ rel_path?);
105
- target = ("#" pchar*) ;
106
- uri = (target | absolute_uri | absolute_path | rel_path) ;
107
-
108
- # common
109
- title = ( '(' default+ >A %{ STORE("title"); } :> ')' ) ;
110
- word = ( alnum | safe | " " ) ;
111
- mspace = ( ( " " | "\t" | LF )+ ) -- LF{2} ;
112
- mtext = ( chars (mspace chars)* ) ;
113
-
114
-
115
- }%%;
@@ -1,193 +0,0 @@
1
- /*
2
- * redcloth_inline.c.rl
3
- *
4
- * Copyright (C) 2009 Jason Garber
5
- */
6
- #include <ruby.h>
7
- #include "redcloth.h"
8
-
9
- %%{
10
-
11
- machine redcloth_inline;
12
- include redcloth_common "redcloth_common.c.rl";
13
- include redcloth_inline "redcloth_inline.rl";
14
-
15
- }%%
16
-
17
- %% write data nofinal;
18
-
19
- VALUE
20
- red_pass(VALUE self, VALUE regs, VALUE ref, ID meth, VALUE refs)
21
- {
22
- VALUE txt = rb_hash_aref(regs, ref);
23
- if (!NIL_P(txt)) rb_hash_aset(regs, ref, redcloth_inline2(self, txt, refs));
24
- return rb_funcall(self, meth, 1, regs);
25
- }
26
-
27
- VALUE
28
- red_parse_attr(VALUE self, VALUE regs, VALUE ref)
29
- {
30
- VALUE txt = rb_hash_aref(regs, ref);
31
- VALUE new_regs = redcloth_attributes(self, txt);
32
- return rb_funcall(regs, rb_intern("update"), 1, new_regs);
33
- }
34
-
35
- VALUE
36
- red_parse_link_attr(VALUE self, VALUE regs, VALUE ref)
37
- {
38
- VALUE txt = rb_hash_aref(regs, ref);
39
- VALUE new_regs = red_parse_title(redcloth_link_attributes(self, txt), ref);
40
-
41
- return rb_funcall(regs, rb_intern("update"), 1, new_regs);
42
- }
43
-
44
- VALUE
45
- red_parse_image_attr(VALUE self, VALUE regs, VALUE ref)
46
- {
47
-
48
- return red_parse_title(regs, ref);
49
- }
50
-
51
- VALUE
52
- red_parse_title(VALUE regs, VALUE ref)
53
- {
54
- // Store title/alt
55
- VALUE txt = rb_hash_aref(regs, ref);
56
- if ( txt != Qnil ) {
57
- char *p = RSTRING_PTR(txt) + RSTRING_LEN(txt);
58
- if (*(p - 1) == ')') {
59
- char level = -1;
60
- p--;
61
- while (p > RSTRING_PTR(txt) && level < 0) {
62
- switch(*(p - 1)) {
63
- case '(': ++level; break;
64
- case ')': --level; break;
65
- }
66
- --p;
67
- }
68
- VALUE title = STR_NEW(p + 1, RSTRING_PTR(txt) + RSTRING_LEN(txt) - 2 - p );
69
- if (p > RSTRING_PTR(txt) && *(p - 1) == ' ') --p;
70
- if (p != RSTRING_PTR(txt)) {
71
- rb_hash_aset(regs, ref, STR_NEW(RSTRING_PTR(txt), p - RSTRING_PTR(txt) ));
72
- rb_hash_aset(regs, ID2SYM(rb_intern("title")), title);
73
- }
74
- }
75
- }
76
- return regs;
77
- }
78
-
79
- VALUE
80
- red_pass_code(VALUE self, VALUE regs, VALUE ref, ID meth)
81
- {
82
- VALUE txt = rb_hash_aref(regs, ref);
83
- if (!NIL_P(txt)) {
84
- VALUE txt2 = STR_NEW2("");
85
- rb_str_cat_escaped_for_preformatted(self, txt2, RSTRING_PTR(txt), RSTRING_PTR(txt) + RSTRING_LEN(txt));
86
- rb_hash_aset(regs, ref, txt2);
87
- }
88
- return rb_funcall(self, meth, 1, regs);
89
- }
90
-
91
- VALUE
92
- red_block(VALUE self, VALUE regs, VALUE block, VALUE refs)
93
- {
94
- ID method;
95
- VALUE fallback;
96
- VALUE sym_text = ID2SYM(rb_intern("text"));
97
- VALUE btype = rb_hash_aref(regs, ID2SYM(rb_intern("type")));
98
- block = rb_funcall(block, rb_intern("strip"), 0);
99
- if ((!NIL_P(block)) && !NIL_P(btype))
100
- {
101
- method = rb_str_intern(btype);
102
- if (method == ID2SYM(rb_intern("notextile"))) {
103
- rb_hash_aset(regs, sym_text, block);
104
- } else {
105
- rb_hash_aset(regs, sym_text, redcloth_inline2(self, block, refs));
106
- }
107
- if (rb_ary_includes(rb_funcall(self, rb_intern("formatter_methods"), 0), method)) {
108
- block = rb_funcall(self, SYM2ID(method), 1, regs);
109
- } else {
110
- fallback = rb_hash_aref(regs, ID2SYM(rb_intern("fallback")));
111
- if (!NIL_P(fallback)) {
112
- rb_str_append(fallback, rb_hash_aref(regs, sym_text));
113
- CLEAR_REGS();
114
- rb_hash_aset(regs, sym_text, fallback);
115
- }
116
- block = rb_funcall(self, rb_intern("p"), 1, regs);
117
- }
118
- }
119
- return block;
120
- }
121
-
122
- VALUE
123
- red_blockcode(VALUE self, VALUE regs, VALUE block)
124
- {
125
- VALUE btype = rb_hash_aref(regs, ID2SYM(rb_intern("type")));
126
- if (RSTRING_LEN(block) > 0)
127
- {
128
- rb_hash_aset(regs, ID2SYM(rb_intern("text")), block);
129
- block = rb_funcall(self, rb_intern(RSTRING_PTR(btype)), 1, regs);
130
- }
131
- return block;
132
- }
133
-
134
- void
135
- red_inc(VALUE regs, VALUE ref)
136
- {
137
- int aint = 0;
138
- VALUE aval = rb_hash_aref(regs, ref);
139
- if (aval != Qnil) aint = NUM2INT(aval);
140
- rb_hash_aset(regs, ref, INT2NUM(aint + 1));
141
- }
142
-
143
- VALUE
144
- redcloth_inline(self, p, pe, refs)
145
- VALUE self;
146
- char *p, *pe;
147
- VALUE refs;
148
- {
149
- int cs, act;
150
- char *ts = NULL, *te = NULL, *reg = NULL, *eof = NULL;
151
- char *orig_p = p;
152
- VALUE block = STR_NEW2("");
153
- VALUE regs = Qnil;
154
-
155
- %% write init;
156
-
157
- %% write exec;
158
-
159
- return block;
160
- }
161
-
162
- /** Append characters to a string, escaping (&, <, >, ", ') using the formatter's escape method.
163
- * @param str ruby string
164
- * @param ts start of character buffer to append
165
- * @param te end of character buffer
166
- */
167
- void
168
- rb_str_cat_escaped(self, str, ts, te)
169
- VALUE self, str;
170
- char *ts, *te;
171
- {
172
- VALUE source_str = STR_NEW(ts, te-ts);
173
- VALUE escaped_str = rb_funcall(self, rb_intern("escape"), 1, source_str);
174
- rb_str_concat(str, escaped_str);
175
- }
176
-
177
- void
178
- rb_str_cat_escaped_for_preformatted(self, str, ts, te)
179
- VALUE self, str;
180
- char *ts, *te;
181
- {
182
- VALUE source_str = STR_NEW(ts, te-ts);
183
- VALUE escaped_str = rb_funcall(self, rb_intern("escape_pre"), 1, source_str);
184
- rb_str_concat(str, escaped_str);
185
- }
186
-
187
- VALUE
188
- redcloth_inline2(self, str, refs)
189
- VALUE self, str, refs;
190
- {
191
- StringValue(str);
192
- return redcloth_inline(self, RSTRING_PTR(str), RSTRING_PTR(str) + RSTRING_LEN(str) + 1, refs);
193
- }