diff --git a/ext/redcloth_scan/redcloth.h b/ext/redcloth_scan/redcloth.h index 10779df9..53c204f5 100644 --- a/ext/redcloth_scan/redcloth.h +++ b/ext/redcloth_scan/redcloth.h @@ -62,7 +62,7 @@ VALUE red_pass_code(VALUE, VALUE, VALUE, ID); #define PARSE_ATTR(A) red_parse_attr(self, regs, ID2SYM(rb_intern(A))) #define PARSE_LINK_ATTR(A) red_parse_link_attr(self, regs, ID2SYM(rb_intern(A))) #define PARSE_IMAGE_ATTR(A) red_parse_image_attr(self, regs, ID2SYM(rb_intern(A))) -#define PASS_CODE(H, A, T, O) rb_str_append(H, red_pass_code(self, regs, ID2SYM(rb_intern(A)), rb_intern(T))) +#define PASS_CODE(H, A, T) rb_str_append(H, red_pass_code(self, regs, ID2SYM(rb_intern(A)), rb_intern(T))) #define ADD_BLOCK() \ rb_str_append(html, red_block(self, regs, block, refs)); \ extend = Qnil; \ diff --git a/ext/redcloth_scan/redcloth_attributes.rb.rl b/ext/redcloth_scan/redcloth_attributes.rb.rl index 547f6cca..8bcd96c3 100644 --- a/ext/redcloth_scan/redcloth_attributes.rb.rl +++ b/ext/redcloth_scan/redcloth_attributes.rb.rl @@ -13,51 +13,44 @@ }%% module RedCloth - module RedclothAttributes - include BaseScanner - - def write_attributes_machine - %%{ - # All other variables become local, letting Ruby garbage collect them. This - # prevents us from having to manually reset them. - - variable data @data; - variable p @p; - variable pe @pe; - variable cs @cs; - variable ts @ts; - variable te @te; - - write data nofinal; - }%% - end + class RedclothAttributes < BaseScanner + class << self + def redcloth_attribute_parser(machine, data) + @data = data + @regs = {} + @p = 0 + @pe = @data.length - def redcloth_attribute_parser(machine, data) - %% write init; #% - - @data = data - @regs = {} - @p = 0 - @pe = @data.length + %% write init; #% - cs = machine + cs = machine - %% write exec; #% + %% write exec; #% - return @regs - end + return @regs + end - def redcloth_attributes(str) - write_attributes_machine - self.cs = self.redcloth_attributes_en_inline - return redcloth_attribute_parser(cs, str) - end + def redcloth_attributes(str) + self.cs = self.redcloth_attributes_en_inline + return redcloth_attribute_parser(cs, str) + end - def redcloth_link_attributes(str) - write_attributes_machine - self.cs = self.redcloth_attributes_en_link_says; - return redcloth_attribute_parser(cs, str) + def redcloth_link_attributes(str) + self.cs = self.redcloth_attributes_en_link_says; + return redcloth_attribute_parser(cs, str) + end end + %%{ + variable data @data; + variable p @p; + variable pe @pe; + variable cs @cs; + variable ts @ts; + variable te @te; + + write data nofinal; + }%% + end end \ No newline at end of file diff --git a/ext/redcloth_scan/redcloth_common.rl b/ext/redcloth_scan/redcloth_common.rl index b206ad9f..1ff56957 100644 --- a/ext/redcloth_scan/redcloth_common.rl +++ b/ext/redcloth_scan/redcloth_common.rl @@ -2,8 +2,8 @@ machine redcloth_common; - action A { @reg = p; } - action B { @bck = p; } + action A { @reg = @p; } + action B { @bck = @p; } action T { STORE("text"); } action X { CLEAR_REGS(); RESET_REG(); } action cat { CAT(block); } diff --git a/ext/redcloth_scan/redcloth_inline.rb.rl b/ext/redcloth_scan/redcloth_inline.rb.rl index b6ca71e0..20571677 100644 --- a/ext/redcloth_scan/redcloth_inline.rb.rl +++ b/ext/redcloth_scan/redcloth_inline.rb.rl @@ -12,109 +12,101 @@ }%% module RedCloth - module RedclothInline - include BaseScanner - - def red_parse_attr(regs, ref) - txt = regs[ref] - new_regs = redcloth_attributes(txt) - return regs.update(new_regs) - end + class RedclothInline < BaseScanner + class << self + + def red_parse_attr(regs, ref) + txt = regs[ref.to_sym] + new_regs = redcloth_attributes(txt) + return regs.update(new_regs) + end - def red_parse_link_attr(regs, ref) - txt = regs[ref] - new_regs = red_parse_title(redcloth_link_attributes(txt), ref) + def red_parse_link_attr(regs, ref) + txt = regs[ref.to_sym] + new_regs = red_parse_title(redcloth_link_attributes(txt), ref) - return regs.update(new_regs) - end + return regs.update(new_regs) + end - def red_parse_image_attr(regs, ref) - return red_parse_title(regs, ref); - end + def red_parse_image_attr(regs, ref) + return red_parse_title(regs, ref); + end - def red_parse_title(regs, ref) - # Store title/alt - name = regs[ref] - if ( !name.nil? ) - s = name.to_s - p = s.length - if (s[p - 1,1] == ')') - level = -1 - p -= 1 - while (p > 0 && level < 0) do - case s[p - 1, 1] - when '('; level += 1 - when ')'; level -= 1 - end + def red_parse_title(regs, ref) + # Store title/alt + name = regs[ref.to_sym] + if ( !name.nil? ) + s = name.to_s + p = s.length + if (s[p - 1,1] == ')') + level = -1 p -= 1 - end - title = s[p + 1, s.length - 1] - p -= 1 if (p > 0 && s[p - 1, 1] == ' ') - if (p != 0) - regs[ref] = s[0, p] - regs[:title] = title + while (p > 0 && level < 0) do + case s[p - 1, 1] + when '('; level += 1 + when ')'; level -= 1 + end + p -= 1 + end + title = s[p + 1, s.length - 1] + p -= 1 if (p > 0 && s[p - 1, 1] == ' ') + if (p != 0) + regs[ref.to_sym] = s[0, p] + regs[:title] = title + end end end + return regs; end - return regs; - end - def red_pass_code(regs, ref, meth) - txt = regs[ref] - if (!txt.nil?) - txt2 = "" - rb_str_cat_escaped_for_preformatted(txt2, text) - regs[ref] = txt2 + def red_pass_code(regs, ref, meth) + txt = regs[ref.to_sym] + if (!txt.nil?) + txt2 = "" + rb_str_cat_escaped_for_preformatted(txt2, text) + regs[ref.to_sym] = txt2 + end + return self.call(meth, regs) end - return self.call(meth, regs) - end - def redcloth_inline(data, refs) - @data = data - @p = 0 - @pe = @data.length - write_inline_machine - @orig_data = @data.dup - @block = "" + def redcloth_inline(textile_doc, data, refs) + @textile_doc = textile_doc + @data = data + @refs = refs + @p = 0 + @pe = @data.length + @orig_data = @data.dup + CLEAR_REGS() + @block = "" - # From RedclothScan; not sure all are necessary - @refs = refs - @block = "" - CLEAR_REGS() - - %% write exec; - ##% + %% write init; + %% write exec; + ##% - return block - end + return block + end - def redcloth_attributes(str) - return self.clone.extend(RedCloth::RedclothAttributes).redcloth_attributes(str) - end - def redcloth_link_attributes(str) - return self.clone.extend(RedCloth::RedclothAttributes).redcloth_link_attributes(str) - end - + def redcloth_attributes(str) + return RedCloth::RedclothAttributes.redcloth_attributes(str) + end + def redcloth_link_attributes(str) + return RedCloth::RedclothAttributes.redcloth_link_attributes(str) + end - def redcloth_inline2(str, refs) - return redcloth_inline(str, refs); + def redcloth_inline2(textile_doc, str, refs) + return redcloth_inline(textile_doc, str, refs); + end end - def write_inline_machine - %%{ - # All other variables become local, letting Ruby garbage collect them. This - # prevents us from having to manually reset them. - - variable data @data; - variable p @p; - variable pe @pe; - variable cs @cs; - variable ts @ts; - variable te @te; + %%{ + variable data @data; + variable p @p; + variable pe @pe; + variable cs @cs; + variable ts @ts; + variable te @te; - write data nofinal; - write init; - }%%## - end + write data nofinal; + }%%## end end \ No newline at end of file diff --git a/ext/redcloth_scan/redcloth_inline.rl b/ext/redcloth_scan/redcloth_inline.rl index a0a6f502..4d4e1451 100644 --- a/ext/redcloth_scan/redcloth_inline.rl +++ b/ext/redcloth_scan/redcloth_inline.rl @@ -101,7 +101,7 @@ link { PARSE_LINK_ATTR("name"); PASS(block, "name", "link"); }; bracketed_link { PARSE_LINK_ATTR("name"); PASS(block, "name", "link"); }; - code { PARSE_ATTR("text"); PASS_CODE(block, "text", "code", opts); }; + code { PARSE_ATTR("text"); PASS_CODE(block, "text", "code"); }; code_tag_start { CAT(block); fgoto code_tag; }; notextile { INLINE(block, "notextile"); }; strong { PARSE_ATTR("text"); PASS(block, "text", "strong"); }; diff --git a/ext/redcloth_scan/redcloth_scan.rb.rl b/ext/redcloth_scan/redcloth_scan.rb.rl index f1ab263a..522f6215 100644 --- a/ext/redcloth_scan/redcloth_scan.rb.rl +++ b/ext/redcloth_scan/redcloth_scan.rb.rl @@ -17,326 +17,323 @@ }%% module RedCloth - module BaseScanner - attr_accessor :p, :pe, :refs - attr_reader :data - attr_accessor :orig_data, :cs, :act, :nest, :ts, :te, :reg, :bck, :eof, - :html, :table, :block, :regs - attr_accessor :list_layout, :list_type, :list_index, :list_continue, :listm, - :refs_found, :plain_block + class BaseScanner + class << self + attr_accessor :p, :pe, :refs + attr_reader :data + attr_accessor :orig_data, :cs, :act, :nest, :ts, :te, :reg, :bck, :eof, + :html, :table, :block, :regs + attr_accessor :list_layout, :list_type, :list_index, :list_continue, :listm, + :refs_found, :plain_block - def CLEAR_REGS() - @regs = {} - end - def RESET_REG() - @reg = nil - end - def CAT(h) - h << data[ts, te-ts] - end - def CLEAR(h) - h.replace("") - end - def RSTRIP_BANG(h) - h.rstrip! - end - def SET_PLAIN_BLOCK(t) - @plain_block = t - end - def RESET_TYPE() - @regs[:type] = @plain_block - end - def INLINE(h, t) - h << self.send(t, @regs) - end - def DONE(h) - @html << h - CLEAR(h) - CLEAR_REGS() - end - def PASS(h, a, t) - h << red_pass(@regs, a.to_sym, t, @refs) - end - def PARSE_ATTR(a) - red_parse_attr(@regs, a) - end - def PARSE_LINK_ATTR(a) - red_parse_link_attr(@regs, a) - end - def PARSE_IMAGE_ATTR(a) - red_parse_image_attr(@regs, a) - end - def PASS_CODE(h, a, t, o) - h << red_pass_code(@regs, a, t) - end - def ADD_BLOCK() - @html << red_block(@regs, @block, @refs) - @extend = nil - CLEAR(@block) - CLEAR_REGS() - end - def ADD_EXTENDED_BLOCK() - @html << red_block(@regs, @block, @refs) - CLEAR(@block) - end - def END_EXTENDED() - @extend = nil - CLEAR_REGS() - end - def ADD_BLOCKCODE() - @html << red_blockcode(@regs, @block) - CLEAR(@block) - CLEAR_REGS() - end - def ADD_EXTENDED_BLOCKCODE() - @html << red_blockcode(@regs, @block) - CLEAR(@block) - end - def ASET(t, v) - @regs[t] = v - end - def AINC(t) - red_inc(@regs, t) - end - def INC(n) - n += 1 - end - def SET_ATTRIBUTES() - SET_ATTRIBUTE("class_buf", "class") - SET_ATTRIBUTE("id_buf", "id") - SET_ATTRIBUTE("lang_buf", "lang") - SET_ATTRIBUTE("style_buf", "style") - end - def SET_ATTRIBUTE(b, a) - @regs[a] = @regs[b] unless @regs[b].nil? - end - def TRANSFORM(t) - if (@p > @reg && @reg >= @ts) - str = redcloth_transform(reg, p, @refs) - @regs[t] = str - # /*printf("TRANSFORM(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/ \ - else - @regs[t] = nil + def STR_NEW(p,n) + @data[p, p+n] end - end - def STORE(t) - if (@p > @reg && @reg >= @ts) - str = @data[@reg, @p - @reg] - @regs[t] = str - # /*printf("STORE(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/ \ - else - @regs[t] = nil + def CLEAR_REGS() + @regs = {} end - end - def STORE_B(t) - if (@p > @bck && @bck >= @ts) - str = @data[@bck, @p - @bck] - @regs[t] = str - # /*printf("STORE_B(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/ \ - else - @regs[t] = nil + def RESET_REG() + @reg = nil end - end - def STORE_URL(t) - if (@p > @reg && @reg >= @ts) - punct = true - while (@p > @reg && punct) - case @data[@p - 1, 1] - when ')' - temp_p = @p - 1 - level = -1 - while (temp_p > @reg) - case @data[temp_p - 1, 1] - when '('; level += 1 - when ')'; level -= 1 + def CAT(h) + h << data[ts, te-ts] + end + def CLEAR(h) + h.replace("") + end + def RSTRIP_BANG(h) + h.rstrip! + end + def SET_PLAIN_BLOCK(t) + @plain_block = t + end + def RESET_TYPE() + @regs[:type] = @plain_block + end + def INLINE(h, t) + h << @textile_doc.send(t, @regs) + end + def DONE(h) + @html << h + CLEAR(h) + CLEAR_REGS() + end + def PASS(h, a, t) + h << red_pass(@regs, a.to_sym, t, @refs) + end + def PARSE_ATTR(a) + red_parse_attr(@regs, a) + end + def PARSE_LINK_ATTR(a) + red_parse_link_attr(@regs, a) + end + def PARSE_IMAGE_ATTR(a) + red_parse_image_attr(@regs, a) + end + def PASS_CODE(h, a, t) + h << red_pass_code(@regs, a, t) + end + def ADD_BLOCK() + @html << red_block(@regs, @block, @refs) + @extend = nil + CLEAR(@block) + CLEAR_REGS() + end + def ADD_EXTENDED_BLOCK() + @html << red_block(@regs, @block, @refs) + CLEAR(@block) + end + def END_EXTENDED() + @extend = nil + CLEAR_REGS() + end + def ADD_BLOCKCODE() + @html << red_blockcode(@regs, @block) + CLEAR(@block) + CLEAR_REGS() + end + def ADD_EXTENDED_BLOCKCODE() + @html << red_blockcode(@regs, @block) + CLEAR(@block) + end + def ASET(t, v) + @regs[t.to_sym] = v + end + def AINC(t) + red_inc(@regs, t) + end + def INC(n) + n += 1 + end + def SET_ATTRIBUTES() + SET_ATTRIBUTE("class_buf", "class") + SET_ATTRIBUTE("id_buf", "id") + SET_ATTRIBUTE("lang_buf", "lang") + SET_ATTRIBUTE("style_buf", "style") + end + def SET_ATTRIBUTE(b, a) + @regs[a] = @regs[b] unless @regs[b].nil? + end + def TRANSFORM(t) + if (@p > @reg && @reg >= @ts) + str = redcloth_transform(reg, p, @refs) + @regs[t.to_sym] = str + # /*printf("TRANSFORM(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/ \ + else + @regs[t.to_sym] = nil + end + end + def STORE(t) + if (@p > @reg && @reg >= @ts) + str = @data[@reg, @p - @reg] + @regs[t.to_sym] = str + # /*printf("STORE(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/ \ + else + @regs[t.to_sym] = nil + end + end + def STORE_B(t) + if (@p > @bck && @bck >= @ts) + str = @data[@bck, @p - @bck] + @regs[t.to_sym] = str + # /*printf("STORE_B(" T ") '%s' (p:'%s' reg:'%s')\n", RSTRING_PTR(str), p, reg);*/ \ + else + @regs[t.to_sym] = nil + end + end + def STORE_URL(t) + if (@p > @reg && @reg >= @ts) + punct = true + while (@p > @reg && punct) + case @data[@p - 1, 1] + when ')' + temp_p = @p - 1 + level = -1 + while (temp_p > @reg) + case @data[temp_p - 1, 1] + when '('; level += 1 + when ')'; level -= 1 + end + temp_p -= 1 end - temp_p -= 1 - end - if (level == 0) - punct = false + if (level == 0) + punct = false + else + @p -= 1 + end + when '!', '"', '#', '$', '%', ']', '[', '&', '\'', + '*', '+', ',', '-', '.', '(', ':', ';', '=', + '?', '@', '\\', '^', '_', '`', '|', '~' + @p -= 1 else - @p -= 1 + punct = false end - when '!', '"', '#', '$', '%', ']', '[', '&', '\'', - '*', '+', ',', '-', '.', '(', ':', ';', '=', - '?', '@', '\\', '^', '_', '`', '|', '~' - @p -= 1 - else - punct = false end + @te = @p + end + STORE(t) + if ( ! @refs.nil? && @refs.has_key?(@regs[t.to_sym]) ) + @regs[t.to_sym] = @refs[@regs[t.to_sym]] end - @te = @p end - STORE(t) - if ( ! @refs.nil? && @refs.has_key?(@regs[t]) ) - @regs[t] = @refs[@regs[t]] + def STORE_LINK_ALIAS() + @refs_found[@regs[:text]] = @regs[:href] end - end - def STORE_LINK_ALIAS() - @refs_found[@regs[:text]] = @regs[:href] - end - def CLEAR_LIST() - @list_layout = [] - end - def LIST_ITEM() - aint = 0 - aval = @list_index[@nest-1] - aint = aval.to_i unless aval.nil? - if (@list_type == "ol") - @list_index[@nest-1] = aint + 1 - end - if (@nest > @list_layout.length) - listm = sprintf("%s_open", @list_type) - if (list_continue) - @list_continue = false - @regs[:start] = @list_index[@nest-1] - else - start = @regs[:start] - if (start.nil?) - @list_index[@nest-1] = 1 + def CLEAR_LIST() + @list_layout = [] + end + def LIST_ITEM() + aint = 0 + aval = @list_index[@nest-1] + aint = aval.to_i unless aval.nil? + if (@list_type == "ol") + @list_index[@nest-1] = aint + 1 + end + if (@nest > @list_layout.length) + listm = sprintf("%s_open", @list_type) + if (list_continue) + @list_continue = false + @regs[:start] = @list_index[@nest-1] else - start_num = start.to_i - @list_index[@nest-1] = start_num + start = @regs[:start] + if (start.nil?) + @list_index[@nest-1] = 1 + else + start_num = start.to_i + @list_index[@nest-1] = start_num + end end + @regs[:nest] = @nest + @html << @textile_doc.send(listm, @regs) + @list_layout[@nest-1] = @list_type + CLEAR_REGS() + ASET("first", "true") end - @regs[:nest] = @nest - @html << self.send(listm, @regs) - @list_layout[@nest-1] = @list_type - CLEAR_REGS() - ASET("first", "true") - end - LIST_CLOSE() - @regs[:nest] = @list_layout.length - ASET("type", "li_open") - end - def LIST_CLOSE() - while (@nest < @list_layout.length) + LIST_CLOSE() @regs[:nest] = @list_layout.length - end_list = @list_layout.pop - if (!end_list.nil?) - listm = sprintf("%s_close", end_list) - @html << self.send(listm, @regs) + ASET("type", "li_open") + end + def LIST_CLOSE() + while (@nest < @list_layout.length) + @regs[:nest] = @list_layout.length + end_list = @list_layout.pop + if (!end_list.nil?) + listm = sprintf("%s_close", end_list) + @html << @textile_doc.send(listm, @regs) + end end end - end - def red_pass(regs, ref, meth, refs) - txt = regs[ref] - regs[ref] = redcloth_inline2(txt, refs) if (!txt.nil?) - return self.send(meth, regs) - end + def red_pass(regs, ref, meth, refs) + txt = regs[ref] + regs[ref] = RedCloth::RedclothInline.redcloth_inline2(@textile_doc, txt, refs) if (!txt.nil?) + return @textile_doc.send(meth, regs) + end - def red_inc(regs, ref) - aint = 0 - aval = regs[ref] - aint = aval.to_i if (!aval.nil?) - regs[ref] = aint + 1 - end + def red_inc(regs, ref) + aint = 0 + aval = regs[ref] + aint = aval.to_i if (!aval.nil?) + regs[ref] = aint + 1 + end - def red_block(regs, block, refs) - sym_text = :text - btype = regs[:type] - block = block.strip - if (!block.nil? && !btype.nil?) - method = btype.intern - if (method == :notextile) - regs[sym_text] = block - else - regs[sym_text] = redcloth_inline2(block, refs) - end - if (self.formatter_methods.includes? method) - block = self.send(method, regs) - else - fallback = regs[:fallback] - if (!fallback.nil?) - fallback << regs[sym_text] - CLEAR_REGS() - regs[sym_text] = fallback + def red_block(regs, block, refs) + sym_text = :text + btype = regs[:type] + block = block.strip + if (!block.nil? && !btype.nil?) + method = btype.intern + if (method == :notextile) + regs[sym_text] = block + else + regs[sym_text] = RedCloth::RedclothInline.redcloth_inline2(@textile_doc, block, refs) + end + if (@textile_doc.send(:formatter_methods).include? method) #FIXME: This is a hack to get around private method. + block = @textile_doc.send(method, regs) + else + fallback = regs[:fallback] + if (!fallback.nil?) + fallback << regs[sym_text] + CLEAR_REGS() + regs[sym_text] = fallback + end + block = @textile_doc.p(regs); end - block = self.p(regs); end + return block end - return block - end - def red_blockcode(regs, block) - btype = regs[:type] - if (block.length > 0) - regs[:text] = block - block = self.send(btype, regs) + def red_blockcode(regs, block) + btype = regs[:type] + if (block.length > 0) + regs[:text] = block + block = @textile_doc.send(btype, regs) + end + return block end - return block - end - def rb_str_cat_escaped(str, ts, te) - source_str = STR_NEW(ts, te-ts); - escaped_str = self.send(:escape, source_str) #FIXME: This is a hack to get around private method. - # escaped_str = self.escape(source_str) - str << escaped_str - end + def rb_str_cat_escaped(str, ts, te) + source_str = STR_NEW(ts, te-ts); + escaped_str = @textile_doc.send(:escape, source_str) #FIXME: This is a hack to get around private method. + str << escaped_str + end - def rb_str_cat_escaped_for_preformatted(str, ts, te) - source_str = STR_NEW(ts, te-ts); - escaped_str = self.send(:escape_pre, source_str) #FIXME: This is a hack to get around private method. - str << escaped_str + def rb_str_cat_escaped_for_preformatted(str, ts, te) + source_str = STR_NEW(ts, te-ts); + escaped_str = @textile_doc.send(:escape_pre, source_str) #FIXME: This is a hack to get around private method. + str << escaped_str + end end - end - module RedclothScan - include BaseScanner - - def transform(data, refs) - write_transform_machine - - @data = data - @p = 0 - @pe = @data.length - @refs = refs - @orig_data = data.dup - @nest = 0 - @html = "" - @table = "" - @block = "" - CLEAR_REGS() + class RedclothScan < BaseScanner + class << self + def transform(textile_doc, data, refs) + @textile_doc = textile_doc + @data = data + @refs = refs + @p = 0 + @pe = @data.length + @orig_data = data.dup + @nest = 0 + @html = "" + @table = "" + @block = "" + CLEAR_REGS() - @list_layout = nil - @list_index = []; - @list_continue = false; - SET_PLAIN_BLOCK("p") - @extend = nil - @listm = [] - @refs_found = {} + @list_layout = nil + @list_index = []; + @list_continue = false; + SET_PLAIN_BLOCK("p") + @extend = nil + @listm = [] + @refs_found = {} - %% write init; + %% write init; - %% write exec; + %% write exec; - ADD_BLOCK() if (block.length > 0) + ADD_BLOCK() if (block.length > 0) - if ( refs.nil? && !refs_found.empty? ) - return redcloth_transform(orig_data, refs_found) - else - after_transform(html) - return html + if ( refs.nil? && !refs_found.empty? ) + return transform(@textile_doc, orig_data, refs_found) + else + @textile_doc.send(:after_transform, html) + return html + end end end - def write_transform_machine - %%{ - # All other variables become local, letting Ruby garbage collect them. This - # prevents us from having to manually reset them. + %%{ + variable data @data; + variable p @p; + variable pe @pe; + variable cs @cs; + variable ts @ts; + variable te @te; - variable data @data; - variable p @p; - variable pe @pe; - variable cs @cs; - variable ts @ts; - variable te @te; - - write data nofinal; - }%%## - end + write data nofinal; + }%%## end class TextileDoc < String @@ -354,17 +351,13 @@ module RedCloth class ParseError < Exception; end - def redcloth_transform(data, refs) - return self.clone.extend(RedCloth::RedclothScan).transform(data, refs) - end - - def redcloth_transform2(str) - before_transform(str) - return redcloth_transform(str, nil); + def redcloth_transform2(textile_doc) + before_transform(textile_doc) + return RedCloth::RedclothScan.transform(self, textile_doc, nil) end - def redcloth_inline2(str, refs) - return self.clone.extend(RedCloth::RedclothInline).redcloth_inline2(str, refs) + def redcloth_inline2(textile_doc, refs) + return RedCloth::RedclothInline.redcloth_inline2(self, textile_doc, refs) end def html_esc(str, level=nil) @@ -401,10 +394,5 @@ module RedCloth return str end - - def STR_NEW(p,n) - @data[p, p+n] - end - end end \ No newline at end of file