lib/trac-wiki/parser.rb in trac-wiki-0.3.14 vs lib/trac-wiki/parser.rb in trac-wiki-0.3.15
- old
+ new
@@ -134,10 +134,11 @@
MACRO_END_REX = /\A(.*?) ( \}\} | \{\{ ( \$[\$\.\w]+ | [\#!\/]\w* | \w+) )/mx
# Create a new Parser instance.
def initialize(options = nil)
init_macros
+ @env = Env.new(self)
@macros = true
@allowed_schemes = %w(http https ftp ftps)
macro_commands = options.delete :macro_commands
@macro_commands.merge! macro_commands if ! macro_commands.nil?
@no_escape = nil
@@ -196,10 +197,11 @@
'!yset' => proc { |env| env[env.expand_arg(0)] = YAML.load(env.arg(1)); '' },
'!sub' => proc { |env| pat = env.expand_arg(1)
pat = Regexp.new(pat[1..-2]) if pat =~ /\A\/.*\/\Z/
env.expand_arg(0).gsub(pat, env.expand_arg(2))
},
+ '!macpos' => proc { |env| "#{env.at('lineno')}.#{env.at('offset')}-#{env.at('elineno')}.#{env.at('eoffset')}" },
'!for' => proc { |env| i_name = env.arg(0)
top = env.arg(1)
tmpl = env.arg(2)
#print "top#{top}\n"
if top =~ /^\d+/
@@ -480,11 +482,10 @@
# r: expanded macro , rest of str, count lines taken from str
# sideefect: parse result of macro
def parse_macro(macro_name, str, offset, macro_name_size)
raise "offset is nil" if offset.nil?
raise "offset is nil" if macro_name_size.nil?
- @env = Env.new(self) if @env.nil?
@env.atput('offset', offset)
@env.atput('lineno', @line_no)
begin
mac_out, rest, lines, rest_offset = @env.parse_macro_all(macro_name, str, macro_name_size)
raise "lines is nil" if lines.nil?
@@ -673,13 +674,14 @@
end
end
def _parse_attrs_to_hash(str)
ret = {}
+ @env.atput('lineno', @line_no);
while str =~ /\A\s*(\w+)\s*=\s*'([^>']*)'/ ||
str =~ /\A\s*(\w+)\s*=\s*"([^>"]*)"/ ||
str =~ /\A\s*(\w+)\s*=\s*(\S*)/
- ret[$1] = $2
+ ret[$1] = @env.expand($2)
str = $'
end
ret
end