RedCloth 4.1.9 → 4.2.0

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 (70) 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 +5 -6
  6. data/ext/redcloth_scan/redcloth.h +38 -13
  7. data/ext/redcloth_scan/redcloth_attributes.c +349 -383
  8. data/ext/redcloth_scan/redcloth_inline.c +4769 -16591
  9. data/ext/redcloth_scan/redcloth_scan.c +21592 -9540
  10. data/lib/redcloth.rb +9 -3
  11. data/lib/redcloth/formatters/html.rb +2 -2
  12. data/lib/redcloth/formatters/latex.rb +99 -54
  13. data/lib/redcloth/formatters/latex_entities.yml +2 -2
  14. data/lib/redcloth/version.rb +9 -4
  15. data/lib/tasks/pureruby.rake +12 -0
  16. data/spec/custom_tags_spec.rb +50 -0
  17. data/spec/differs/inline.rb +48 -0
  18. data/{test/test_erb.rb → spec/erb_spec.rb} +6 -9
  19. data/spec/extension_spec.rb +26 -0
  20. data/{test → spec/fixtures}/basic.yml +90 -4
  21. data/{test → spec/fixtures}/code.yml +29 -0
  22. data/{test → spec/fixtures}/definitions.yml +0 -0
  23. data/{test → spec/fixtures}/extra_whitespace.yml +0 -0
  24. data/{test → spec/fixtures}/filter_html.yml +0 -0
  25. data/{test → spec/fixtures}/filter_pba.yml +0 -0
  26. data/{test → spec/fixtures}/html.yml +15 -0
  27. data/{test → spec/fixtures}/images.yml +16 -6
  28. data/{test → spec/fixtures}/instiki.yml +0 -0
  29. data/{test → spec/fixtures}/links.yml +7 -1
  30. data/{test → spec/fixtures}/lists.yml +162 -1
  31. data/{test → spec/fixtures}/poignant.yml +0 -0
  32. data/{test → spec/fixtures}/sanitize_html.yml +0 -0
  33. data/{test → spec/fixtures}/table.yml +121 -23
  34. data/{test → spec/fixtures}/textism.yml +44 -15
  35. data/{test → spec/fixtures}/threshold.yml +6 -14
  36. data/spec/formatters/class_filtered_html_spec.rb +7 -0
  37. data/spec/formatters/filtered_html_spec.rb +7 -0
  38. data/spec/formatters/html_no_breaks_spec.rb +9 -0
  39. data/spec/formatters/html_spec.rb +13 -0
  40. data/spec/formatters/id_filtered_html_spec.rb +7 -0
  41. data/spec/formatters/latex_spec.rb +13 -0
  42. data/spec/formatters/lite_mode_html_spec.rb +7 -0
  43. data/spec/formatters/no_span_caps_html_spec.rb +7 -0
  44. data/spec/formatters/sanitized_html_spec.rb +7 -0
  45. data/spec/formatters/style_filtered_html_spec.rb +7 -0
  46. data/spec/parser_spec.rb +95 -0
  47. data/spec/spec.opts +3 -0
  48. data/spec/spec_helper.rb +42 -0
  49. metadata +40 -49
  50. data/ext/mingw-rbconfig.rb +0 -176
  51. data/ext/redcloth_scan/redcloth_attributes.c.rl +0 -55
  52. data/ext/redcloth_scan/redcloth_attributes.java.rl +0 -95
  53. data/ext/redcloth_scan/redcloth_attributes.rl +0 -33
  54. data/ext/redcloth_scan/redcloth_common.c.rl +0 -18
  55. data/ext/redcloth_scan/redcloth_common.java.rl +0 -18
  56. data/ext/redcloth_scan/redcloth_common.rl +0 -115
  57. data/ext/redcloth_scan/redcloth_inline.c.rl +0 -193
  58. data/ext/redcloth_scan/redcloth_inline.java.rl +0 -140
  59. data/ext/redcloth_scan/redcloth_inline.rl +0 -156
  60. data/ext/redcloth_scan/redcloth_scan.c.rl +0 -228
  61. data/ext/redcloth_scan/redcloth_scan.java.rl +0 -577
  62. data/ext/redcloth_scan/redcloth_scan.rl +0 -320
  63. data/extras/ragel_profiler.rb +0 -73
  64. data/test/helper.rb +0 -108
  65. data/test/test_custom_tags.rb +0 -58
  66. data/test/test_extensions.rb +0 -31
  67. data/test/test_formatters.rb +0 -24
  68. data/test/test_parser.rb +0 -73
  69. data/test/test_restrictions.rb +0 -41
  70. data/test/validate_fixtures.rb +0 -74
@@ -1,577 +0,0 @@
1
- /*
2
- * redcloth_scan.java.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.Arity;
19
- import org.jruby.runtime.Block;
20
- import org.jruby.runtime.CallbackFactory;
21
- import org.jruby.runtime.builtin.IRubyObject;
22
- import org.jruby.exceptions.RaiseException;
23
- import org.jruby.runtime.load.BasicLibraryService;
24
- import org.jruby.util.ByteList;
25
-
26
- public class RedclothScanService implements BasicLibraryService {
27
-
28
- public static class Base {
29
-
30
- public void CLEAR_LIST() {
31
- list_layout = runtime.newArray();
32
- }
33
-
34
- public void LIST_ITEM() {
35
- int aint = 0;
36
- IRubyObject aval = ((RubyArray)list_index).entry(nest-1);
37
- if(!aval.isNil()) { aint = RubyNumeric.fix2int(aval); }
38
- if(list_type.equals("ol")) {
39
- ((RubyArray)list_index).store(nest-1, runtime.newFixnum(aint + 1));
40
- }
41
-
42
- if(nest > ((RubyArray)list_layout).getLength()) {
43
- listm = list_type + "_open";
44
- if(list_continue == 1) {
45
- list_continue = 0;
46
- ((RubyHash)regs).aset(runtime.newSymbol("start"), ((RubyArray)list_index).entry(nest-1));
47
- } else {
48
- IRubyObject start = ((RubyHash)regs).aref(runtime.newSymbol("start"));
49
- if(start.isNil()) {
50
- ((RubyArray)list_index).store(nest-1, runtime.newFixnum(1));
51
- } else {
52
- IRubyObject start_num = start.callMethod(runtime.getCurrentContext(), "to_i");
53
- ((RubyArray)list_index).store(nest-1, start_num);
54
- }
55
- }
56
- ((RubyHash)regs).aset(runtime.newSymbol("nest"), runtime.newFixnum(nest));
57
- ((RubyString)html).append(self.callMethod(runtime.getCurrentContext(), listm, regs));
58
- ((RubyArray)list_layout).store(nest-1, runtime.newString(list_type));
59
- regs = RubyHash.newHash(runtime);
60
- ASET("first", "true");
61
- }
62
- LIST_CLOSE();
63
- ((RubyHash)regs).aset(runtime.newSymbol("nest"), ((RubyArray)list_layout).length());
64
- ASET("type", "li_open");
65
- }
66
-
67
- public void LIST_CLOSE() {
68
- while(nest < ((RubyArray)list_layout).getLength()) {
69
- ((RubyHash)regs).aset(runtime.newSymbol("nest"), ((RubyArray)list_layout).length());
70
- IRubyObject end_list = ((RubyArray)list_layout).pop(runtime.getCurrentContext());
71
- if(!end_list.isNil()) {
72
- String s = end_list.convertToString().toString();
73
- listm = s + "_close";
74
- ((RubyString)html).append(self.callMethod(runtime.getCurrentContext(), listm, regs));
75
- }
76
- }
77
- }
78
-
79
- public void TRANSFORM(String T) {
80
- if(p > reg && reg >= ts) {
81
- IRubyObject str = RedclothScanService.transform(self, data, reg, p-reg, refs);
82
- ((RubyHash)regs).aset(runtime.newSymbol(T), str);
83
- } else {
84
- ((RubyHash)regs).aset(runtime.newSymbol(T), runtime.getNil());
85
- }
86
- }
87
-
88
- public IRubyObject red_pass(IRubyObject self, IRubyObject regs, IRubyObject ref, String meth, IRubyObject refs) {
89
- IRubyObject txt = ((RubyHash)regs).aref(ref);
90
- if(!txt.isNil()) {
91
- ((RubyHash)regs).aset(ref, inline2(self, txt, refs));
92
- }
93
- return self.callMethod(self.getRuntime().getCurrentContext(), meth, regs);
94
- }
95
-
96
-
97
- public void PASS(IRubyObject H, String A, String T) {
98
- ((RubyString)H).append(red_pass(self, regs, runtime.newSymbol(A), T, refs));
99
- }
100
-
101
-
102
- public void STORE_LINK_ALIAS() {
103
- ((RubyHash)refs_found).aset(((RubyHash)regs).aref(runtime.newSymbol("text")), ((RubyHash)regs).aref(runtime.newSymbol("href")));
104
- }
105
-
106
- public void STORE_URL(String T) {
107
- if(p > reg && reg >= ts) {
108
- boolean punct = true;
109
- while(p > reg && punct) {
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;
123
- case '!': case '"': case '#': case '$': case '%': case ']': case '[': case '&': case '\'':
124
- case '*': case '+': case ',': case '-': case '.': case '(': case ':':
125
- case ';': case '=': case '?': case '@': case '\\': case '^': case '_':
126
- case '`': case '|': case '~': p--; break;
127
- default: punct = false;
128
- }
129
- }
130
- te = p;
131
- }
132
-
133
- STORE(T);
134
-
135
- if(!refs.isNil() && refs.callMethod(runtime.getCurrentContext(), "has_key?", ((RubyHash)regs).aref(runtime.newSymbol(T))).isTrue()) {
136
- ((RubyHash)regs).aset(runtime.newSymbol(T), ((RubyHash)refs).aref(((RubyHash)regs).aref(runtime.newSymbol(T))));
137
- }
138
- }
139
-
140
- public void red_inc(IRubyObject regs, IRubyObject ref) {
141
- int aint = 0;
142
- IRubyObject aval = ((RubyHash)regs).aref(ref);
143
- if(!aval.isNil()) {
144
- aint = RubyNumeric.fix2int(aval);
145
- }
146
- ((RubyHash)regs).aset(ref, regs.getRuntime().newFixnum(aint+1));
147
- }
148
-
149
- public IRubyObject red_blockcode(IRubyObject self, IRubyObject regs, IRubyObject block) {
150
- Ruby runtime = self.getRuntime();
151
- IRubyObject btype = ((RubyHash)regs).aref(runtime.newSymbol("type"));
152
- if(((RubyString)block).getByteList().realSize > 0) {
153
- ((RubyHash)regs).aset(runtime.newSymbol("text"), block);
154
- block = self.callMethod(runtime.getCurrentContext(), btype.asJavaString(), regs);
155
- }
156
- return block;
157
- }
158
-
159
- public IRubyObject red_block(IRubyObject self, IRubyObject regs, IRubyObject block, IRubyObject refs) {
160
- Ruby runtime = self.getRuntime();
161
- RubySymbol method;
162
- IRubyObject sym_text = runtime.newSymbol("text");
163
- IRubyObject btype = ((RubyHash)regs).aref(runtime.newSymbol("type"));
164
- block = block.callMethod(runtime.getCurrentContext(), "strip");
165
-
166
- if(!block.isNil() && !btype.isNil()) {
167
- method = btype.convertToString().intern();
168
-
169
- if(method == runtime.newSymbol("notextile")) {
170
- ((RubyHash)regs).aset(sym_text, block);
171
- } else {
172
- ((RubyHash)regs).aset(sym_text, inline2(self, block, refs));
173
- }
174
-
175
- IRubyObject formatterMethods = ((RubyObject)self).callMethod(runtime.getCurrentContext(), "formatter_methods");
176
- if( ((RubyArray)formatterMethods).includes(runtime.getCurrentContext(), method) ) {
177
- block = self.callMethod(runtime.getCurrentContext(), method.asJavaString(), regs);
178
- } else {
179
- IRubyObject fallback = ((RubyHash)regs).aref(runtime.newSymbol("fallback"));
180
- if(!fallback.isNil()) {
181
- ((RubyString)fallback).append(((RubyHash)regs).aref(sym_text));
182
- regs = RubyHash.newHash(runtime);
183
- ((RubyHash)regs).aset(sym_text, fallback);
184
- }
185
- block = self.callMethod(runtime.getCurrentContext(), "p", regs);
186
- }
187
- }
188
-
189
- return block;
190
- }
191
-
192
- public void strCatEscaped(IRubyObject self, IRubyObject str, byte[] data, int ts, int te) {
193
- IRubyObject sourceStr = RubyString.newString(self.getRuntime(), data, ts, te-ts);
194
- IRubyObject escapedStr = self.callMethod(self.getRuntime().getCurrentContext(), "escape", sourceStr);
195
- ((RubyString)str).concat(escapedStr);
196
- }
197
-
198
- public void strCatEscapedForPreformatted(IRubyObject self, IRubyObject str, byte[] data, int ts, int te) {
199
- IRubyObject sourceStr = RubyString.newString(self.getRuntime(), data, ts, te-ts);
200
- IRubyObject escapedStr = self.callMethod(self.getRuntime().getCurrentContext(), "escape_pre", sourceStr);
201
- ((RubyString)str).concat(escapedStr);
202
- }
203
-
204
- public void CLEAR(IRubyObject obj) {
205
- if(block == obj) {
206
- block = RubyString.newEmptyString(runtime);
207
- } else if(html == obj) {
208
- html = RubyString.newEmptyString(runtime);
209
- } else if(table == obj) {
210
- table = RubyString.newEmptyString(runtime);
211
- }
212
- }
213
-
214
- public void ADD_BLOCK() {
215
- ((RubyString)html).append(red_block(self, regs, block, refs));
216
- extend = runtime.getNil();
217
- CLEAR(block);
218
- CLEAR_REGS();
219
- }
220
-
221
- public void CLEAR_REGS() {
222
- regs = RubyHash.newHash(runtime);
223
- }
224
-
225
- public void RESET_REG() {
226
- reg = -1;
227
- }
228
-
229
- public void CAT(IRubyObject H) {
230
- ((RubyString)H).cat(data, ts, te-ts);
231
- }
232
-
233
- public void SET_PLAIN_BLOCK(String T) {
234
- plain_block = runtime.newString(T);
235
- }
236
-
237
- public void RESET_TYPE() {
238
- ((RubyHash)regs).aset(runtime.newSymbol("type"), plain_block);
239
- }
240
-
241
- public void INLINE(IRubyObject H, String T) {
242
- ((RubyString)H).append(self.callMethod(runtime.getCurrentContext(), T, regs));
243
- }
244
-
245
- public void RSTRIP_BANG(IRubyObject H) {
246
- ((RubyString)H).callMethod(runtime.getCurrentContext(), "rstrip!");
247
- }
248
-
249
- public void DONE(IRubyObject H) {
250
- ((RubyString)html).append(H);
251
- CLEAR(H);
252
- CLEAR_REGS();
253
- }
254
-
255
- public void ADD_EXTENDED_BLOCK() {
256
- ((RubyString)html).append(red_block(self, regs, block, refs));
257
- CLEAR(block);
258
- }
259
-
260
- public void ADD_BLOCKCODE() {
261
- ((RubyString)html).append(red_blockcode(self, regs, block));
262
- CLEAR(block);
263
- CLEAR_REGS();
264
- }
265
-
266
- public void ADD_EXTENDED_BLOCKCODE() {
267
- ((RubyString)html).append(red_blockcode(self, regs, block));
268
- CLEAR(block);
269
- }
270
-
271
- public void AINC(String T) {
272
- red_inc(regs, runtime.newSymbol(T));
273
- }
274
-
275
- public void END_EXTENDED() {
276
- extend = runtime.getNil();
277
- CLEAR_REGS();
278
- }
279
-
280
- public boolean IS_NOT_EXTENDED() {
281
- return extend.isNil();
282
- }
283
-
284
- public void ASET(String T, String V) {
285
- ((RubyHash)regs).aset(runtime.newSymbol(T), runtime.newString(V));
286
- }
287
-
288
- public void STORE(String T) {
289
- if(p > reg && reg >= ts) {
290
-
291
- IRubyObject str = RubyString.newString(runtime, data, reg, p-reg);
292
- ((RubyHash)regs).aset(runtime.newSymbol(T), str);
293
- } else {
294
- ((RubyHash)regs).aset(runtime.newSymbol(T), runtime.getNil());
295
- }
296
- }
297
-
298
- public void STORE_B(String T) {
299
- if(p > bck && bck >= ts) {
300
- IRubyObject str = RubyString.newString(runtime, data, bck, p-bck);
301
- ((RubyHash)regs).aset(runtime.newSymbol(T), str);
302
- } else {
303
- ((RubyHash)regs).aset(runtime.newSymbol(T), runtime.getNil());
304
- }
305
- }
306
-
307
- public IRubyObject self;
308
- public byte[] data;
309
- public int p, pe;
310
- public IRubyObject refs;
311
-
312
- public Ruby runtime;
313
- public int orig_p, orig_pe;
314
- public int cs, act, nest;
315
- public int ts = -1;
316
- public int te = -1;
317
- public int reg = -1;
318
- public int bck = -1;
319
- public int eof = -1;
320
-
321
- public IRubyObject html;
322
- public IRubyObject table;
323
- public IRubyObject block;
324
- public IRubyObject regs;
325
-
326
- public IRubyObject list_layout;
327
- public String list_type = null;
328
- public IRubyObject list_index;
329
- public int list_continue = 0;
330
- public IRubyObject plain_block;
331
- public IRubyObject extend;
332
- public String listm = "";
333
- public IRubyObject refs_found;
334
- }
335
-
336
- private static class Transformer extends Base {
337
- %%{
338
-
339
- machine redcloth_scan;
340
- include redcloth_common "redcloth_common.java.rl";
341
-
342
- action extend { extend = ((RubyHash)regs).aref(runtime.newSymbol("type")); }
343
-
344
- include redcloth_scan "redcloth_scan.rl";
345
-
346
- }%%
347
-
348
- %% write data nofinal;
349
-
350
- public Transformer(IRubyObject self, byte[] data, int p, int pe, IRubyObject refs) {
351
- if(p+pe > data.length) {
352
- throw new RuntimeException("BLAHAHA");
353
- }
354
- this.self = self;
355
-
356
- // This is GROSS but necessary for EOF matching
357
- this.data = new byte[pe+1];
358
- System.arraycopy(data, p, this.data, 0, pe);
359
- this.data[pe] = 0;
360
-
361
- this.p = 0;
362
- this.pe = pe+1;
363
- this.eof = this.pe;
364
- this.orig_p = 0;
365
- this.orig_pe = this.pe;
366
-
367
- this.refs = refs;
368
-
369
- runtime = self.getRuntime();
370
-
371
- html = RubyString.newEmptyString(runtime);
372
- table = RubyString.newEmptyString(runtime);
373
- block = RubyString.newEmptyString(runtime);
374
- CLEAR_REGS();
375
-
376
- list_layout = runtime.getNil();
377
- list_index = runtime.newArray();
378
- SET_PLAIN_BLOCK("p");
379
- extend = runtime.getNil();
380
- refs_found = RubyHash.newHash(runtime);
381
- }
382
-
383
- public IRubyObject transform() {
384
- %% write init;
385
-
386
- %% write exec;
387
-
388
- if(((RubyString)block).getByteList().realSize > 0) {
389
- ADD_BLOCK();
390
- }
391
-
392
- if(refs.isNil() && !refs_found.callMethod(runtime.getCurrentContext(), "empty?").isTrue()) {
393
- return RedclothScanService.transform(self, data, orig_p, orig_pe, refs_found);
394
- } else {
395
- self.callMethod(self.getRuntime().getCurrentContext(), "after_transform", html);
396
- return html;
397
- }
398
- }
399
- }
400
-
401
- public static IRubyObject transform(IRubyObject self, byte[] data, int p, int pe, IRubyObject refs) {
402
- return new Transformer(self, data, p, pe, refs).transform();
403
- }
404
-
405
- public static IRubyObject inline2(IRubyObject workingCopy, IRubyObject self, IRubyObject refs) {
406
- return RedclothInline.inline2(workingCopy, self, refs);
407
- }
408
-
409
- public static IRubyObject transform2(IRubyObject self, IRubyObject str) {
410
- RubyString ss = str.convertToString();
411
- self.callMethod(self.getRuntime().getCurrentContext(), "before_transform", ss);
412
- return transform(self, ss.getByteList().bytes(), ss.getByteList().begin, ss.getByteList().realSize, self.getRuntime().getNil());
413
- }
414
-
415
- @JRubyMethod
416
- public static IRubyObject to(IRubyObject self, IRubyObject formatter) {
417
- Ruby runtime = self.getRuntime();
418
- self.callMethod(runtime.getCurrentContext(), "delete!", runtime.newString("\r"));
419
- IRubyObject workingCopy = self.rbClone();
420
-
421
- ((RubyObject)workingCopy).extend(new IRubyObject[]{formatter});
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
-
428
- if(workingCopy.callMethod(runtime.getCurrentContext(), "lite_mode").isTrue()) {
429
- return inline2(workingCopy, self, RubyHash.newHash(runtime));
430
- } else {
431
- return transform2(workingCopy, self);
432
- }
433
- }
434
-
435
- @JRubyMethod(rest=true)
436
- public static IRubyObject html_esc(IRubyObject self, IRubyObject[] args) {
437
- Ruby runtime = self.getRuntime();
438
- IRubyObject str = runtime.getNil(),
439
- level = runtime.getNil();
440
- if(Arity.checkArgumentCount(runtime, args, 1, 2) == 2) {
441
- level = args[1];
442
- }
443
- str = args[0];
444
-
445
- IRubyObject new_str = RubyString.newEmptyString(runtime);
446
- if(str.isNil()) {
447
- return new_str;
448
- }
449
-
450
- ByteList bl = str.convertToString().getByteList();
451
-
452
- if(bl.realSize == 0) {
453
- return new_str;
454
- }
455
-
456
- byte[] bytes = bl.bytes;
457
- int ts = bl.begin;
458
- int te = ts + bl.realSize;
459
- int t = ts, t2 = ts;
460
- String ch = null;
461
-
462
- if(te <= ts) {
463
- return new_str;
464
- }
465
-
466
- while(t2 < te) {
467
- ch = null;
468
- // normal + pre
469
- switch(bytes[t2]) {
470
- case '&': ch = "amp"; break;
471
- case '>': ch = "gt"; break;
472
- case '<': ch = "lt"; break;
473
- }
474
-
475
- // normal (non-pre)
476
- if(level != runtime.newSymbol("html_escape_preformatted")) {
477
- switch(bytes[t2]) {
478
- case '\n': ch = "br"; break;
479
- case '"' : ch = "quot"; break;
480
- case '\'':
481
- ch = (level == runtime.newSymbol("html_escape_attributes")) ? "apos" : "squot";
482
- break;
483
- }
484
- }
485
-
486
- if(ch != null) {
487
- if(t2 > t) {
488
- ((RubyString)new_str).cat(bytes, t, t2-t);
489
- }
490
- ((RubyString)new_str).concat(self.callMethod(runtime.getCurrentContext(), ch, RubyHash.newHash(runtime)));
491
- t = t2 + 1;
492
- }
493
-
494
- t2++;
495
- }
496
-
497
-
498
- if(t2 > t) {
499
- ((RubyString)new_str).cat(bytes, t, t2-t);
500
- }
501
-
502
- return new_str;
503
- }
504
-
505
- @JRubyMethod
506
- public static IRubyObject latex_esc(IRubyObject self, IRubyObject str) {
507
- Ruby runtime = self.getRuntime();
508
- IRubyObject new_str = RubyString.newEmptyString(runtime);
509
-
510
- if(str.isNil()) {
511
- return new_str;
512
- }
513
-
514
- ByteList bl = str.convertToString().getByteList();
515
-
516
- if(bl.realSize == 0) {
517
- return new_str;
518
- }
519
-
520
- byte[] bytes = bl.bytes;
521
- int ts = bl.begin;
522
- int te = ts + bl.realSize;
523
- int t = ts;
524
- int t2 = ts;
525
- String ch = null;
526
-
527
- while(t2 < te) {
528
- ch = null;
529
-
530
- switch(bytes[t2]) {
531
- case '{': ch = "#123"; break;
532
- case '}': ch = "#125"; break;
533
- case '\\': ch = "#92"; break;
534
- case '#': ch = "#35"; break;
535
- case '$': ch = "#36"; break;
536
- case '%': ch = "#37"; break;
537
- case '&': ch = "amp"; break;
538
- case '_': ch = "#95"; break;
539
- case '^': ch = "circ"; break;
540
- case '~': ch = "tilde"; break;
541
- case '<': ch = "lt"; break;
542
- case '>': ch = "gt"; break;
543
- case '\n': ch = "#10"; break;
544
- }
545
-
546
- if(ch != null) {
547
- if(t2 > t) {
548
- ((RubyString)new_str).cat(bytes, t, t2-t);
549
- }
550
- IRubyObject opts = RubyHash.newHash(runtime);
551
- ((RubyHash)opts).aset(runtime.newSymbol("text"), runtime.newString(ch));
552
- ((RubyString)new_str).concat(self.callMethod(runtime.getCurrentContext(), "entity", opts));
553
- t = t2 + 1;
554
- }
555
-
556
- t2++;
557
- }
558
-
559
- if(t2 > t) {
560
- ((RubyString)new_str).cat(bytes, t, t2-t);
561
- }
562
-
563
- return new_str;
564
- }
565
-
566
- public boolean basicLoad(final Ruby runtime) throws IOException {
567
- Init_redcloth_scan(runtime);
568
- return true;
569
- }
570
-
571
- public static void Init_redcloth_scan(Ruby runtime) {
572
- RubyModule mRedCloth = runtime.defineModule("RedCloth");
573
- RubyClass super_RedCloth = mRedCloth.defineClassUnder("TextileDoc", runtime.getString(), runtime.getString().getAllocator());
574
- super_RedCloth.defineAnnotatedMethods(RedclothScanService.class);
575
- super_RedCloth.defineClassUnder("ParseError",runtime.getClass("Exception"),runtime.getClass("Exception").getAllocator());
576
- }
577
- }