parity-RedCloth 4.2.9
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.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.rspec +1 -0
- data/CHANGELOG +265 -0
- data/COPYING +18 -0
- data/Gemfile +7 -0
- data/README.rdoc +215 -0
- data/Rakefile +18 -0
- data/bin/redcloth +28 -0
- data/doc/textile_reference.html +631 -0
- data/ext/redcloth_scan/extconf.rb +6 -0
- data/ext/redcloth_scan/redcloth.h +220 -0
- data/ext/redcloth_scan/redcloth_attributes.c +650 -0
- data/ext/redcloth_scan/redcloth_inline.c +8153 -0
- data/ext/redcloth_scan/redcloth_scan.c +24407 -0
- data/lib/case_sensitive_require/RedCloth.rb +6 -0
- data/lib/redcloth/erb_extension.rb +27 -0
- data/lib/redcloth/formatters/base.rb +63 -0
- data/lib/redcloth/formatters/html.rb +352 -0
- data/lib/redcloth/formatters/latex.rb +331 -0
- data/lib/redcloth/formatters/latex_entities.yml +2414 -0
- data/lib/redcloth/textile_doc.rb +113 -0
- data/lib/redcloth/version.rb +34 -0
- data/lib/redcloth.rb +45 -0
- data/lib/tasks/pureruby.rake +17 -0
- data/redcloth.gemspec +54 -0
- data/spec/benchmark_spec.rb +15 -0
- data/spec/custom_tags_spec.rb +50 -0
- data/spec/erb_spec.rb +10 -0
- data/spec/extension_spec.rb +26 -0
- data/spec/fixtures/basic.yml +1028 -0
- data/spec/fixtures/code.yml +257 -0
- data/spec/fixtures/definitions.yml +82 -0
- data/spec/fixtures/extra_whitespace.yml +64 -0
- data/spec/fixtures/filter_html.yml +177 -0
- data/spec/fixtures/filter_pba.yml +20 -0
- data/spec/fixtures/html.yml +348 -0
- data/spec/fixtures/images.yml +279 -0
- data/spec/fixtures/instiki.yml +38 -0
- data/spec/fixtures/links.yml +291 -0
- data/spec/fixtures/lists.yml +462 -0
- data/spec/fixtures/poignant.yml +89 -0
- data/spec/fixtures/sanitize_html.yml +42 -0
- data/spec/fixtures/table.yml +434 -0
- data/spec/fixtures/textism.yml +509 -0
- data/spec/fixtures/threshold.yml +762 -0
- data/spec/formatters/class_filtered_html_spec.rb +7 -0
- data/spec/formatters/filtered_html_spec.rb +7 -0
- data/spec/formatters/html_no_breaks_spec.rb +9 -0
- data/spec/formatters/html_spec.rb +13 -0
- data/spec/formatters/id_filtered_html_spec.rb +7 -0
- data/spec/formatters/latex_spec.rb +13 -0
- data/spec/formatters/lite_mode_html_spec.rb +7 -0
- data/spec/formatters/no_span_caps_html_spec.rb +7 -0
- data/spec/formatters/sanitized_html_spec.rb +7 -0
- data/spec/formatters/style_filtered_html_spec.rb +7 -0
- data/spec/parser_spec.rb +102 -0
- data/spec/spec_helper.rb +36 -0
- data/tasks/compile.rake +47 -0
- data/tasks/gems.rake +37 -0
- data/tasks/ragel_extension_task.rb +127 -0
- data/tasks/release.rake +15 -0
- data/tasks/rspec.rake +13 -0
- data/tasks/rvm.rake +79 -0
- metadata +239 -0
| @@ -0,0 +1,220 @@ | |
| 1 | 
            +
            #ifndef redcloth_h
         | 
| 2 | 
            +
            #define redcloth_h
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            #ifndef RARRAY_LEN
         | 
| 5 | 
            +
            #define RARRAY_LEN(arr)  RARRAY(arr)->len
         | 
| 6 | 
            +
            #define RSTRING_LEN(str) RSTRING(str)->len
         | 
| 7 | 
            +
            #define RSTRING_PTR(str) RSTRING(str)->ptr
         | 
| 8 | 
            +
            #endif
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
            // Different string conversions for ruby 1.8 and ruby 1.9. For 1.9, 
         | 
| 12 | 
            +
            // we need to set the encoding of the string.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            // For Ruby 1.9
         | 
| 15 | 
            +
            #ifdef HAVE_RUBY_ENCODING_H
         | 
| 16 | 
            +
            #include "ruby/encoding.h"
         | 
| 17 | 
            +
            #define STR_NEW(p,n) rb_enc_str_new((p),(n),rb_enc_from_index(ENCODING_GET(self)))
         | 
| 18 | 
            +
            #define STR_NEW2(p) rb_enc_str_new((p),strlen(p),rb_enc_from_index(ENCODING_GET(self)))
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            // For Ruby 1.8
         | 
| 21 | 
            +
            #else
         | 
| 22 | 
            +
            #define STR_NEW(p,n) rb_str_new((p),(n))
         | 
| 23 | 
            +
            #define STR_NEW2(p) rb_str_new2((p))
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            #endif
         | 
| 26 | 
            +
             | 
| 27 | 
            +
             | 
| 28 | 
            +
            /* variable defs */
         | 
| 29 | 
            +
            #ifndef redcloth_scan_c
         | 
| 30 | 
            +
            extern VALUE super_ParseError, mRedCloth, super_RedCloth;
         | 
| 31 | 
            +
            extern int SYM_escape_preformatted;
         | 
| 32 | 
            +
            #endif
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            /* function defs */
         | 
| 35 | 
            +
            void rb_str_cat_escaped(VALUE self, VALUE str, char *ts, char *te);
         | 
| 36 | 
            +
            void rb_str_cat_escaped_for_preformatted(VALUE self, VALUE str, char *ts, char *te);
         | 
| 37 | 
            +
            VALUE redcloth_inline(VALUE, char *, char *, VALUE);
         | 
| 38 | 
            +
            VALUE redcloth_inline2(VALUE, VALUE, VALUE);
         | 
| 39 | 
            +
            VALUE redcloth_attribute_parser(int, VALUE, char *, char *);
         | 
| 40 | 
            +
            VALUE redcloth_attributes(VALUE, VALUE);
         | 
| 41 | 
            +
            VALUE redcloth_link_attributes(VALUE, VALUE);
         | 
| 42 | 
            +
            VALUE red_parse_title(VALUE, VALUE, VALUE);
         | 
| 43 | 
            +
            VALUE redcloth_transform(VALUE, char *, char *, VALUE);
         | 
| 44 | 
            +
            VALUE redcloth_transform2(VALUE, VALUE);
         | 
| 45 | 
            +
            void red_inc(VALUE, VALUE);
         | 
| 46 | 
            +
            VALUE red_block(VALUE, VALUE, VALUE, VALUE);
         | 
| 47 | 
            +
            VALUE red_blockcode(VALUE, VALUE, VALUE);
         | 
| 48 | 
            +
            VALUE red_pass(VALUE, VALUE, VALUE, ID, VALUE);
         | 
| 49 | 
            +
            VALUE red_pass_code(VALUE, VALUE, VALUE, ID);
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            /* parser macros */
         | 
| 52 | 
            +
            #define CLEAR_REGS()   regs = rb_hash_new(); attr_regs = rb_hash_new();
         | 
| 53 | 
            +
            #define RESET_REG()    reg = NULL
         | 
| 54 | 
            +
            #define MARK()         reg = p;
         | 
| 55 | 
            +
            #define MARK_B()       bck = p;
         | 
| 56 | 
            +
            #define MARK_ATTR()    attr_reg = p;
         | 
| 57 | 
            +
            #define CAT(H)         rb_str_cat(H, ts, te-ts)
         | 
| 58 | 
            +
            #define CLEAR(H)       H = STR_NEW2("")
         | 
| 59 | 
            +
            #define RSTRIP_BANG(H)      rb_funcall(H, rb_intern("rstrip!"), 0)
         | 
| 60 | 
            +
            #define SET_PLAIN_BLOCK(T) plain_block = STR_NEW2(T)
         | 
| 61 | 
            +
            #define RESET_TYPE(T)  rb_hash_aset(regs, ID2SYM(rb_intern("type")), plain_block)
         | 
| 62 | 
            +
            #define INLINE(H, T)   rb_str_append(H, rb_funcall(self, rb_intern(T), 1, regs))
         | 
| 63 | 
            +
            #define DONE(H)        rb_str_append(html, H); CLEAR(H); CLEAR_REGS()
         | 
| 64 | 
            +
            #define PASS(H, A, T)  rb_str_append(H, red_pass(self, regs, ID2SYM(rb_intern(A)), rb_intern(T), refs))
         | 
| 65 | 
            +
            #define PARSE_ATTR(A)  red_parse_attr(self, regs, ID2SYM(rb_intern(A)))
         | 
| 66 | 
            +
            #define PARSE_LINK_ATTR(A)  red_parse_link_attr(self, regs, ID2SYM(rb_intern(A)))
         | 
| 67 | 
            +
            #define PARSE_IMAGE_ATTR(A)  red_parse_image_attr(self, regs, ID2SYM(rb_intern(A)))
         | 
| 68 | 
            +
            #define PASS_CODE(H, A, T) rb_str_append(H, red_pass_code(self, regs, ID2SYM(rb_intern(A)), rb_intern(T)))
         | 
| 69 | 
            +
            #define ADD_BLOCK() \
         | 
| 70 | 
            +
              rb_str_append(html, red_block(self, regs, block, refs)); \
         | 
| 71 | 
            +
              extend = Qnil; \
         | 
| 72 | 
            +
              CLEAR(block); \
         | 
| 73 | 
            +
              CLEAR_REGS()
         | 
| 74 | 
            +
            #define ADD_EXTENDED_BLOCK()    rb_str_append(html, red_block(self, regs, block, refs)); CLEAR(block);
         | 
| 75 | 
            +
            #define END_EXTENDED()     extend = Qnil; CLEAR_REGS();
         | 
| 76 | 
            +
            #define ADD_BLOCKCODE()    rb_str_append(html, red_blockcode(self, regs, block)); CLEAR(block); CLEAR_REGS()
         | 
| 77 | 
            +
            #define ADD_EXTENDED_BLOCKCODE()    rb_str_append(html, red_blockcode(self, regs, block)); CLEAR(block);
         | 
| 78 | 
            +
            #define ASET(T, V)     rb_hash_aset(regs, ID2SYM(rb_intern(T)), STR_NEW2(V));
         | 
| 79 | 
            +
            #define ATTR_SET(T, V) rb_hash_aset(attr_regs, ID2SYM(rb_intern(T)), STR_NEW2(V));
         | 
| 80 | 
            +
            #define ATTR_INC(T)        red_inc(attr_regs, ID2SYM(rb_intern(T)));
         | 
| 81 | 
            +
            #define INC(N)         N++;
         | 
| 82 | 
            +
            #define SET_ATTRIBUTES() \
         | 
| 83 | 
            +
              SET_ATTRIBUTE("class_buf", "class"); \
         | 
| 84 | 
            +
              SET_ATTRIBUTE("id_buf", "id"); \
         | 
| 85 | 
            +
              SET_ATTRIBUTE("lang_buf", "lang"); \
         | 
| 86 | 
            +
              SET_ATTRIBUTE("style_buf", "style"); \
         | 
| 87 | 
            +
              rb_funcall(regs, rb_intern("merge!"), 1, attr_regs); \
         | 
| 88 | 
            +
              attr_regs = rb_hash_new();
         | 
| 89 | 
            +
            #define SET_ATTRIBUTE(B, A) \
         | 
| 90 | 
            +
              if (rb_hash_aref(regs, ID2SYM(rb_intern(B))) != Qnil) rb_hash_aset(regs, ID2SYM(rb_intern(A)), rb_hash_aref(regs, ID2SYM(rb_intern(B))));
         | 
| 91 | 
            +
            #define TRANSFORM(T) \
         | 
| 92 | 
            +
              if (p > reg && reg >= ts) { \
         | 
| 93 | 
            +
                VALUE str = redcloth_transform(self, reg, p, refs); \
         | 
| 94 | 
            +
                rb_hash_aset(regs, ID2SYM(rb_intern(T)), str); \
         | 
| 95 | 
            +
                /*printf("TRANSFORM(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/  \
         | 
| 96 | 
            +
              } else { \
         | 
| 97 | 
            +
                rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \
         | 
| 98 | 
            +
              }
         | 
| 99 | 
            +
            #define STORE(T)  \
         | 
| 100 | 
            +
              if (p > reg && reg >= ts) { \
         | 
| 101 | 
            +
                VALUE str = STR_NEW(reg, p-reg); \
         | 
| 102 | 
            +
                rb_hash_aset(regs, ID2SYM(rb_intern(T)), str); \
         | 
| 103 | 
            +
                /*printf("STORE(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/  \
         | 
| 104 | 
            +
              } else { \
         | 
| 105 | 
            +
                rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \
         | 
| 106 | 
            +
              }
         | 
| 107 | 
            +
            #define STORE_B(T)  \
         | 
| 108 | 
            +
              if (p > bck && bck >= ts) { \
         | 
| 109 | 
            +
                VALUE str = STR_NEW(bck, p-bck); \
         | 
| 110 | 
            +
                rb_hash_aset(regs, ID2SYM(rb_intern(T)), str); \
         | 
| 111 | 
            +
                /*printf("STORE_B(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/  \
         | 
| 112 | 
            +
              } else { \
         | 
| 113 | 
            +
                rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \
         | 
| 114 | 
            +
              }
         | 
| 115 | 
            +
            #define STORE_ATTR(T)  \
         | 
| 116 | 
            +
              if (p > attr_reg && attr_reg >= ts) { \
         | 
| 117 | 
            +
                VALUE str = STR_NEW(attr_reg, p-attr_reg); \
         | 
| 118 | 
            +
                rb_hash_aset(attr_regs, ID2SYM(rb_intern(T)), str); \
         | 
| 119 | 
            +
                /*printf("STORE_B(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/  \
         | 
| 120 | 
            +
              } else { \
         | 
| 121 | 
            +
                rb_hash_aset(attr_regs, ID2SYM(rb_intern(T)), Qnil); \
         | 
| 122 | 
            +
              }
         | 
| 123 | 
            +
             | 
| 124 | 
            +
            #define STORE_URL(T) \
         | 
| 125 | 
            +
              if (p > reg && reg >= ts) { \
         | 
| 126 | 
            +
                char punct = 1; \
         | 
| 127 | 
            +
                while (p > reg && punct == 1) { \
         | 
| 128 | 
            +
                  switch (*(p - 1)) { \
         | 
| 129 | 
            +
                    case ')': \
         | 
| 130 | 
            +
                      { /*needed to keep inside chars scoped for less memory usage*/\
         | 
| 131 | 
            +
                        char *temp_p = p - 1; \
         | 
| 132 | 
            +
                        signed char level = -1; \
         | 
| 133 | 
            +
                        while (temp_p > reg) { \
         | 
| 134 | 
            +
                          switch(*(temp_p - 1)) { \
         | 
| 135 | 
            +
                            case '(': ++level; break; \
         | 
| 136 | 
            +
                            case ')': --level; break; \
         | 
| 137 | 
            +
                          } \
         | 
| 138 | 
            +
                          --temp_p; \
         | 
| 139 | 
            +
                        } \
         | 
| 140 | 
            +
                        if (level == 0) { punct = 0; } else { --p; } \
         | 
| 141 | 
            +
                      } \
         | 
| 142 | 
            +
                      break;  \
         | 
| 143 | 
            +
                    case '!': case '"': case '#': case '$': case '%': case ']': case '[': case '&': case '\'': \
         | 
| 144 | 
            +
                    case '*': case '+': case ',': case '-': case '.': case '(':  case ':':  \
         | 
| 145 | 
            +
                    case ';': case '=': case '?': case '@': case '\\': case '^': case '_': \
         | 
| 146 | 
            +
                    case '`': case '|': case '~': p--; break; \
         | 
| 147 | 
            +
                    default: punct = 0; \
         | 
| 148 | 
            +
                  } \
         | 
| 149 | 
            +
                } \
         | 
| 150 | 
            +
                te = p; \
         | 
| 151 | 
            +
              } \
         | 
| 152 | 
            +
              STORE(T); \
         | 
| 153 | 
            +
              if ( !NIL_P(refs) && rb_funcall(refs, rb_intern("has_key?"), 1, rb_hash_aref(regs, ID2SYM(rb_intern(T)))) ) { \
         | 
| 154 | 
            +
                rb_hash_aset(regs, ID2SYM(rb_intern(T)), rb_hash_aref(refs, rb_hash_aref(regs, ID2SYM(rb_intern(T))))); \
         | 
| 155 | 
            +
              }
         | 
| 156 | 
            +
            #define STORE_LINK_ALIAS() \
         | 
| 157 | 
            +
              rb_hash_aset(refs_found, rb_hash_aref(regs, ID2SYM(rb_intern("text"))), rb_hash_aref(regs, ID2SYM(rb_intern("href"))))
         | 
| 158 | 
            +
            #define CLEAR_LIST() list_layout = rb_ary_new()
         | 
| 159 | 
            +
            #define SET_LIST_TYPE(T) list_type = T;
         | 
| 160 | 
            +
            #define NEST() nest ++;
         | 
| 161 | 
            +
            #define RESET_NEST() nest = 0;
         | 
| 162 | 
            +
            #define LIST_LAYOUT() \
         | 
| 163 | 
            +
                int aint = 0; \
         | 
| 164 | 
            +
                VALUE aval = rb_ary_entry(list_index, nest-1); \
         | 
| 165 | 
            +
                if (aval != Qnil) aint = NUM2INT(aval); \
         | 
| 166 | 
            +
                if (strcmp(list_type, "ol") == 0 && nest > 0) \
         | 
| 167 | 
            +
                { \
         | 
| 168 | 
            +
                  rb_ary_store(list_index, nest-1, INT2NUM(aint + 1)); \
         | 
| 169 | 
            +
                } \
         | 
| 170 | 
            +
                if (nest > RARRAY_LEN(list_layout)) \
         | 
| 171 | 
            +
                { \
         | 
| 172 | 
            +
                  SET_ATTRIBUTES(); \
         | 
| 173 | 
            +
                  sprintf(listm, "%s_open", list_type); \
         | 
| 174 | 
            +
                  if (!NIL_P(rb_hash_aref(regs, ID2SYM(rb_intern("list_continue"))))) \
         | 
| 175 | 
            +
                  { \
         | 
| 176 | 
            +
                    rb_hash_aset(regs, ID2SYM(rb_intern("list_continue")), Qnil); \
         | 
| 177 | 
            +
                    rb_hash_aset(regs, ID2SYM(rb_intern("start")), rb_ary_entry(list_index, nest-1)); \
         | 
| 178 | 
            +
                  } \
         | 
| 179 | 
            +
                  else \
         | 
| 180 | 
            +
                  { \
         | 
| 181 | 
            +
                    VALUE start = rb_hash_aref(regs, ID2SYM(rb_intern("start"))); \
         | 
| 182 | 
            +
                    if (NIL_P(start) ) \
         | 
| 183 | 
            +
                    { \
         | 
| 184 | 
            +
                      rb_ary_store(list_index, nest-1, INT2NUM(1)); \
         | 
| 185 | 
            +
                    } \
         | 
| 186 | 
            +
                    else \
         | 
| 187 | 
            +
                    { \
         | 
| 188 | 
            +
                      VALUE start_num = rb_funcall(start,rb_intern("to_i"),0); \
         | 
| 189 | 
            +
                      rb_ary_store(list_index, nest-1, start_num); \
         | 
| 190 | 
            +
                    } \
         | 
| 191 | 
            +
                  } \
         | 
| 192 | 
            +
                  rb_hash_aset(regs, ID2SYM(rb_intern("nest")), INT2NUM(nest)); \
         | 
| 193 | 
            +
                  rb_str_append(html, rb_funcall(self, rb_intern(listm), 1, regs)); \
         | 
| 194 | 
            +
                  rb_ary_store(list_layout, nest-1, STR_NEW2(list_type)); \
         | 
| 195 | 
            +
                  CLEAR_REGS(); \
         | 
| 196 | 
            +
                  ASET("first", "true"); \
         | 
| 197 | 
            +
                } \
         | 
| 198 | 
            +
                LIST_CLOSE(); \
         | 
| 199 | 
            +
                if (nest != 0) LIST_ITEM_CLOSE(); \
         | 
| 200 | 
            +
                CLEAR_REGS(); \
         | 
| 201 | 
            +
                rb_hash_aset(regs, ID2SYM(rb_intern("nest")), INT2NUM(RARRAY_LEN(list_layout))); \
         | 
| 202 | 
            +
                ASET("type", "li_open");
         | 
| 203 | 
            +
            #define LIST_ITEM_CLOSE() \
         | 
| 204 | 
            +
                if ( rb_hash_aref(regs, ID2SYM(rb_intern("first"))) == Qnil ) \
         | 
| 205 | 
            +
                  rb_str_append(html, rb_funcall(self, rb_intern("li_close"), 1, regs));
         | 
| 206 | 
            +
            #define LIST_CLOSE() \
         | 
| 207 | 
            +
                while (nest < RARRAY_LEN(list_layout)) \
         | 
| 208 | 
            +
                { \
         | 
| 209 | 
            +
                  rb_hash_aset(regs, ID2SYM(rb_intern("nest")), INT2NUM(RARRAY_LEN(list_layout))); \
         | 
| 210 | 
            +
                  VALUE end_list = rb_ary_pop(list_layout); \
         | 
| 211 | 
            +
                  if (!NIL_P(end_list)) \
         | 
| 212 | 
            +
                  { \
         | 
| 213 | 
            +
                    StringValue(end_list); \
         | 
| 214 | 
            +
                    sprintf(listm, "%s_close", RSTRING_PTR(end_list)); \
         | 
| 215 | 
            +
                    LIST_ITEM_CLOSE(); \
         | 
| 216 | 
            +
                    rb_str_append(html, rb_funcall(self, rb_intern(listm), 1, regs)); \
         | 
| 217 | 
            +
                  } \
         | 
| 218 | 
            +
                }
         | 
| 219 | 
            +
             | 
| 220 | 
            +
            #endif
         |