Skip to content

Commit

Permalink
Almost working. Maybe should convert them to class methods, though.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber committed Mar 12, 2009
1 parent 2bc308f commit b5dc7e5
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 121 deletions.
36 changes: 26 additions & 10 deletions ext/redcloth_scan/redcloth_attributes.rb.rl
Expand Up @@ -16,30 +16,46 @@ module RedCloth
module RedclothAttributes
include BaseScanner

def initialize
%% write data nofinal;
# % (gets syntax highlighting working again)
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

def redcloth_attribute_parser(machine, data)
regs = {}

%% write init;
%% write init; #%

@data = data
@regs = {}
@p = 0
@pe = @data.length

cs = machine

%% write exec;
%% write exec; #%

return regs
return @regs
end

def redcloth_attributes(str)
cs = redcloth_attributes_en_inline
write_attributes_machine
self.cs = self.redcloth_attributes_en_inline
return redcloth_attribute_parser(cs, str)
end

def redcloth_link_attributes(str)
cs = redcloth_attributes_en_link_says;
write_attributes_machine
self.cs = self.redcloth_attributes_en_link_says;
return redcloth_attribute_parser(cs, str)
end

Expand Down
4 changes: 2 additions & 2 deletions ext/redcloth_scan/redcloth_common.rl
Expand Up @@ -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); }
Expand Down
59 changes: 39 additions & 20 deletions ext/redcloth_scan/redcloth_inline.rb.rl
Expand Up @@ -15,20 +15,15 @@ module RedCloth
module RedclothInline
include BaseScanner

def initialize
%% write data nofinal;
# % (gets syntax highlighting working again)
end

def red_parse_attr(regs, ref)
txt = regs[ref]
new_regs = redcloth_attributes(self, txt)
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(self, txt), ref)
new_regs = red_parse_title(redcloth_link_attributes(txt), ref)

return regs.update(new_regs)
end
Expand Down Expand Up @@ -74,28 +69,52 @@ module RedCloth
return self.call(meth, regs)
end



def redcloth_inline(data, refs)
orig_data = data;
block = ""
regs = nil

%% write init;

@data = data
@p = 0
@pe = @data.length
write_inline_machine
@orig_data = @data.dup
@block = ""

# From RedclothScan; not sure all are necessary
@refs = refs
@block = ""
CLEAR_REGS()

%% write exec;
##%

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

# Append characters to a string, escaping (&, <, >, ", ') using the formatter's escape method.
# @param str ruby string
# @param ts start of character buffer to append
# @param te end of character buffer
#

def redcloth_inline2(str, refs)
return redcloth_inline(str, refs);
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;

write data nofinal;
write init;
}%%##
end
end
end

0 comments on commit b5dc7e5

Please sign in to comment.