jeremy-RedCloth 4.1.1

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.
Files changed (57) hide show
  1. data/CHANGELOG +135 -0
  2. data/COPYING +18 -0
  3. data/Manifest +56 -0
  4. data/README +171 -0
  5. data/Rakefile +205 -0
  6. data/bin/redcloth +28 -0
  7. data/ext/mingw-rbconfig.rb +176 -0
  8. data/ext/redcloth_scan/extconf.rb +9 -0
  9. data/ext/redcloth_scan/redcloth.h +178 -0
  10. data/ext/redcloth_scan/redcloth_attributes.c.rl +56 -0
  11. data/ext/redcloth_scan/redcloth_attributes.java.rl +96 -0
  12. data/ext/redcloth_scan/redcloth_attributes.rl +33 -0
  13. data/ext/redcloth_scan/redcloth_common.c.rl +18 -0
  14. data/ext/redcloth_scan/redcloth_common.java.rl +18 -0
  15. data/ext/redcloth_scan/redcloth_common.rl +111 -0
  16. data/ext/redcloth_scan/redcloth_inline.c.rl +159 -0
  17. data/ext/redcloth_scan/redcloth_inline.java.rl +108 -0
  18. data/ext/redcloth_scan/redcloth_inline.rl +159 -0
  19. data/ext/redcloth_scan/redcloth_scan.c.rl +237 -0
  20. data/ext/redcloth_scan/redcloth_scan.java.rl +573 -0
  21. data/ext/redcloth_scan/redcloth_scan.rl +325 -0
  22. data/extras/ragel_profiler.rb +73 -0
  23. data/lib/case_sensitive_require/RedCloth.rb +6 -0
  24. data/lib/redcloth.rb +37 -0
  25. data/lib/redcloth/erb_extension.rb +27 -0
  26. data/lib/redcloth/formatters/base.rb +57 -0
  27. data/lib/redcloth/formatters/html.rb +353 -0
  28. data/lib/redcloth/formatters/latex.rb +275 -0
  29. data/lib/redcloth/formatters/latex_entities.yml +2414 -0
  30. data/lib/redcloth/textile_doc.rb +103 -0
  31. data/lib/redcloth/version.rb +28 -0
  32. data/setup.rb +1585 -0
  33. data/test/basic.yml +922 -0
  34. data/test/code.yml +229 -0
  35. data/test/definitions.yml +82 -0
  36. data/test/extra_whitespace.yml +64 -0
  37. data/test/filter_html.yml +177 -0
  38. data/test/filter_pba.yml +20 -0
  39. data/test/helper.rb +108 -0
  40. data/test/html.yml +311 -0
  41. data/test/images.yml +254 -0
  42. data/test/instiki.yml +38 -0
  43. data/test/links.yml +275 -0
  44. data/test/lists.yml +283 -0
  45. data/test/poignant.yml +89 -0
  46. data/test/sanitize_html.yml +42 -0
  47. data/test/table.yml +336 -0
  48. data/test/test_custom_tags.rb +58 -0
  49. data/test/test_erb.rb +13 -0
  50. data/test/test_extensions.rb +31 -0
  51. data/test/test_formatters.rb +24 -0
  52. data/test/test_parser.rb +73 -0
  53. data/test/test_restrictions.rb +41 -0
  54. data/test/textism.yml +480 -0
  55. data/test/threshold.yml +772 -0
  56. data/test/validate_fixtures.rb +74 -0
  57. metadata +133 -0
@@ -0,0 +1,96 @@
1
+ /*
2
+ * redcloth_attributes.rl
3
+ *
4
+ * Copyright (C) 2008 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
+ buf = ((RubyHash)regs).aref(runtime.newSymbol(B));
47
+ if(!buf.isNil()) {
48
+ ((RubyHash)regs).aset(runtime.newSymbol(A), buf);
49
+ }
50
+ }
51
+
52
+ private int machine;
53
+ private IRubyObject buf;
54
+
55
+ public RedclothAttributes(int machine, IRubyObject self, byte[] data, int p, int pe) {
56
+ this.runtime = self.getRuntime();
57
+ this.self = self;
58
+
59
+ // This is GROSS but necessary for EOF matching
60
+ this.data = new byte[pe+1];
61
+ System.arraycopy(data, p, this.data, 0, pe);
62
+ this.data[pe] = 0;
63
+
64
+ this.p = 0;
65
+ this.pe = pe+1;
66
+ this.eof = this.pe;
67
+ this.orig_p = 0;
68
+ this.orig_pe = this.pe;
69
+
70
+ this.regs = RubyHash.newHash(runtime);
71
+ this.buf = runtime.getNil();
72
+ this.machine = machine;
73
+ }
74
+
75
+ public IRubyObject parse() {
76
+ %% write init;
77
+
78
+ cs = machine;
79
+
80
+ %% write exec;
81
+
82
+ return regs;
83
+ }
84
+
85
+ public static IRubyObject attributes(IRubyObject self, IRubyObject str) {
86
+ ByteList bl = str.convertToString().getByteList();
87
+ int cs = redcloth_attributes_en_inline;
88
+ return new RedclothAttributes(cs, self, bl.bytes, bl.begin, bl.realSize).parse();
89
+ }
90
+
91
+ public static IRubyObject link_attributes(IRubyObject self, IRubyObject str) {
92
+ ByteList bl = str.convertToString().getByteList();
93
+ int cs = redcloth_attributes_en_link_says;
94
+ return new RedclothAttributes(cs, self, bl.bytes, bl.begin, bl.realSize).parse();
95
+ }
96
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ * redcloth_attributes.rl
3
+ *
4
+ * Copyright (C) 2008 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
+ }%%;
@@ -0,0 +1,18 @@
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
+ }%%;
@@ -0,0 +1,18 @@
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
+ }%%;
@@ -0,0 +1,111 @@
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
+
81
+ # URI tokens (lifted from Mongrel)
82
+ CTL = (cntrl | 127);
83
+ safe = ("$" | "-" | "_" | ".");
84
+ extra = ("!" | "*" | "'" | "(" | ")" | "," | "#");
85
+ reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
86
+ unsafe = (CTL | " " | "\"" | "%" | "<" | ">");
87
+ national = any -- (alpha | digit | reserved | extra | safe | unsafe);
88
+ unreserved = (alpha | digit | safe | extra | national);
89
+ escape = ("%" xdigit xdigit);
90
+ uchar = (unreserved | escape);
91
+ pchar = (uchar | ":" | "@" | "&" | "=" | "+");
92
+ scheme = ( alpha | digit | "+" | "-" | "." )+ ;
93
+ absolute_uri = (scheme ":" (uchar | reserved )*);
94
+ safepath = (pchar* (alpha | digit | safe) pchar*) ;
95
+ path = (safepath ( "/" pchar* )*) ;
96
+ query = ( uchar | reserved )* ;
97
+ param = ( pchar | "/" )* ;
98
+ params = (param ( ";" param )*) ;
99
+ rel_path = (path (";" params)?) ("?" query)?;
100
+ absolute_path = ("/"+ rel_path?);
101
+ target = ("#" pchar*) ;
102
+ uri = (target | absolute_uri | absolute_path | rel_path) ;
103
+
104
+ # common
105
+ title = ( '(' default+ >A %{ STORE("title"); } :> ')' ) ;
106
+ word = ( alnum | safe | " " ) ;
107
+ mspace = ( ( " " | "\t" | LF )+ ) -- LF{2} ;
108
+ mtext = ( chars (mspace chars)* ) ;
109
+
110
+
111
+ }%%;
@@ -0,0 +1,159 @@
1
+ /*
2
+ * redcloth_inline.c.rl
3
+ *
4
+ * Copyright (C) 2008 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 = redcloth_link_attributes(self, txt);
40
+ return rb_funcall(regs, rb_intern("update"), 1, new_regs);
41
+ }
42
+
43
+ VALUE
44
+ red_pass_code(VALUE self, VALUE regs, VALUE ref, ID meth)
45
+ {
46
+ VALUE txt = rb_hash_aref(regs, ref);
47
+ if (!NIL_P(txt)) {
48
+ VALUE txt2 = rb_str_new2("");
49
+ rb_str_cat_escaped_for_preformatted(self, txt2, RSTRING_PTR(txt), RSTRING_PTR(txt) + RSTRING_LEN(txt));
50
+ rb_hash_aset(regs, ref, txt2);
51
+ }
52
+ return rb_funcall(self, meth, 1, regs);
53
+ }
54
+
55
+ VALUE
56
+ red_block(VALUE self, VALUE regs, VALUE block, VALUE refs)
57
+ {
58
+ ID method;
59
+ VALUE fallback;
60
+ VALUE sym_text = ID2SYM(rb_intern("text"));
61
+ VALUE btype = rb_hash_aref(regs, ID2SYM(rb_intern("type")));
62
+ block = rb_funcall(block, rb_intern("strip"), 0);
63
+ if ((!NIL_P(block)) && !NIL_P(btype))
64
+ {
65
+ method = rb_intern(RSTRING_PTR(btype));
66
+ if (method == rb_intern("notextile")) {
67
+ rb_hash_aset(regs, sym_text, block);
68
+ } else {
69
+ rb_hash_aset(regs, sym_text, redcloth_inline2(self, block, refs));
70
+ }
71
+ if (rb_ary_includes(rb_iv_get(self, "@custom_tags"), btype)) {
72
+ block = rb_funcall(self, method, 1, regs);
73
+ } else {
74
+ fallback = rb_hash_aref(regs, ID2SYM(rb_intern("fallback")));
75
+ if (!NIL_P(fallback)) {
76
+ rb_str_append(fallback, rb_hash_aref(regs, sym_text));
77
+ CLEAR_REGS();
78
+ rb_hash_aset(regs, sym_text, fallback);
79
+ }
80
+ block = rb_funcall(self, rb_intern("p"), 1, regs);
81
+ }
82
+ }
83
+ return block;
84
+ }
85
+
86
+ VALUE
87
+ red_blockcode(VALUE self, VALUE regs, VALUE block)
88
+ {
89
+ VALUE btype = rb_hash_aref(regs, ID2SYM(rb_intern("type")));
90
+ if (RSTRING_LEN(block) > 0)
91
+ {
92
+ rb_hash_aset(regs, ID2SYM(rb_intern("text")), block);
93
+ block = rb_funcall(self, rb_intern(RSTRING_PTR(btype)), 1, regs);
94
+ }
95
+ return block;
96
+ }
97
+
98
+ void
99
+ red_inc(VALUE regs, VALUE ref)
100
+ {
101
+ int aint = 0;
102
+ VALUE aval = rb_hash_aref(regs, ref);
103
+ if (aval != Qnil) aint = NUM2INT(aval);
104
+ rb_hash_aset(regs, ref, INT2NUM(aint + 1));
105
+ }
106
+
107
+ VALUE
108
+ redcloth_inline(self, p, pe, refs)
109
+ VALUE self;
110
+ char *p, *pe;
111
+ VALUE refs;
112
+ {
113
+ int cs, act;
114
+ char *ts, *te, *reg, *eof;
115
+ char *orig_p = p, *orig_pe = pe;
116
+ VALUE block = rb_str_new2("");
117
+ VALUE regs = Qnil;
118
+ unsigned int opts = 0;
119
+ VALUE buf = Qnil;
120
+
121
+ %% write init;
122
+
123
+ %% write exec;
124
+
125
+ return block;
126
+ }
127
+
128
+ /** Append characters to a string, escaping (&, <, >, ", ') using the formatter's escape method.
129
+ * @param str ruby string
130
+ * @param ts start of character buffer to append
131
+ * @param te end of character buffer
132
+ */
133
+ void
134
+ rb_str_cat_escaped(self, str, ts, te)
135
+ VALUE self, str;
136
+ char *ts, *te;
137
+ {
138
+ VALUE source_str = rb_str_new(ts, te-ts);
139
+ VALUE escaped_str = rb_funcall(self, rb_intern("escape"), 1, source_str);
140
+ rb_str_concat(str, escaped_str);
141
+ }
142
+
143
+ void
144
+ rb_str_cat_escaped_for_preformatted(self, str, ts, te)
145
+ VALUE self, str;
146
+ char *ts, *te;
147
+ {
148
+ VALUE source_str = rb_str_new(ts, te-ts);
149
+ VALUE escaped_str = rb_funcall(self, rb_intern("escape_pre"), 1, source_str);
150
+ rb_str_concat(str, escaped_str);
151
+ }
152
+
153
+ VALUE
154
+ redcloth_inline2(self, str, refs)
155
+ VALUE self, str, refs;
156
+ {
157
+ StringValue(str);
158
+ return redcloth_inline(self, RSTRING_PTR(str), RSTRING_PTR(str) + RSTRING_LEN(str) + 1, refs);
159
+ }
@@ -0,0 +1,108 @@
1
+ /*
2
+ * redcloth_inline.rl
3
+ *
4
+ * Copyright (C) 2008 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 RedclothInline extends RedclothScanService.Base {
27
+
28
+ %%{
29
+
30
+ machine redcloth_inline;
31
+ include redcloth_common "redcloth_common.java.rl";
32
+ include redcloth_inline "redcloth_inline.rl";
33
+
34
+ }%%
35
+
36
+ %% write data nofinal;
37
+
38
+ public IRubyObject red_pass_code(IRubyObject self, IRubyObject regs, IRubyObject ref, String meth) {
39
+ IRubyObject txt = ((RubyHash)regs).aref(ref);
40
+ if(!txt.isNil()) {
41
+ IRubyObject txt2 = RubyString.newEmptyString(runtime);
42
+ strCatEscapedForPreformatted(self, txt2, ((RubyString)txt).getByteList().bytes, ((RubyString)txt).getByteList().begin, ((RubyString)txt).getByteList().begin + ((RubyString)txt).getByteList().realSize);
43
+ ((RubyHash)regs).aset(ref, txt2);
44
+ }
45
+ return self.callMethod(runtime.getCurrentContext(), meth, regs);
46
+ }
47
+
48
+ public IRubyObject red_parse_attr(IRubyObject self, IRubyObject regs, IRubyObject ref) {
49
+ IRubyObject txt = ((RubyHash)regs).aref(ref);
50
+ IRubyObject new_regs = RedclothAttributes.attributes(self, txt);
51
+ return regs.callMethod(runtime.getCurrentContext(), "update", new_regs);
52
+ }
53
+
54
+ public IRubyObject red_parse_link_attr(IRubyObject self, IRubyObject regs, IRubyObject ref) {
55
+ IRubyObject txt = ((RubyHash)regs).aref(ref);
56
+ IRubyObject new_regs = RedclothAttributes.link_attributes(self, txt);
57
+ return regs.callMethod(runtime.getCurrentContext(), "update", new_regs);
58
+ }
59
+
60
+ public void PASS_CODE(IRubyObject H, String A, String T, int O) {
61
+ ((RubyString)H).append(red_pass_code(self, regs, runtime.newSymbol(A), T));
62
+ }
63
+
64
+ public void PARSE_ATTR(String A) {
65
+ red_parse_attr(self, regs, runtime.newSymbol(A));
66
+ }
67
+
68
+ public void PARSE_LINK_ATTR(String A) {
69
+ red_parse_link_attr(self, regs, runtime.newSymbol(A));
70
+ }
71
+
72
+ private int opts;
73
+ private IRubyObject buf;
74
+
75
+ public RedclothInline(IRubyObject self, byte[] data, int p, int pe, IRubyObject refs) {
76
+ this.runtime = self.getRuntime();
77
+ this.self = self;
78
+
79
+ // This is GROSS but necessary for EOF matching
80
+ this.data = new byte[pe+1];
81
+ System.arraycopy(data, p, this.data, 0, pe);
82
+ this.data[pe] = 0;
83
+
84
+ this.p = 0;
85
+ this.pe = pe+1;
86
+ this.eof = this.pe;
87
+ this.orig_p = 0;
88
+ this.orig_pe = this.pe;
89
+ this.refs = refs;
90
+ this.block = RubyString.newEmptyString(runtime);
91
+ this.regs = runtime.getNil();
92
+ this.opts = 0;
93
+ this.buf = runtime.getNil();
94
+ }
95
+
96
+
97
+ public IRubyObject inline() {
98
+ %% write init;
99
+ %% write exec;
100
+
101
+ return block;
102
+ }
103
+
104
+ public static IRubyObject inline2(IRubyObject self, IRubyObject str, IRubyObject refs) {
105
+ ByteList bl = str.convertToString().getByteList();
106
+ return new RedclothInline(self, bl.bytes, bl.begin, bl.realSize, refs).inline();
107
+ }
108
+ }