in reply to Nested list items
You need to write a parser.
state = [] ARGF.each do |line| state.push :input if line =~ /<input>/ state.push :ordered if line =~ /<ordered-list>/ state.push :bulleted if line =~ /<bulleted-list>/ state.pop if line =~ /<end-list>/ or line =~ /<\/input>/ if line =~ /<item>/ case state.last when :ordered line.gsub!( /<item>/, "<ordered-item>" ) when :bulleted line.gsub!( /<item>/, "<bulleted-item>" ) else ## do nothing end end puts line end
Updated: Tweaked to actually run . . . and again to tweak state transitions to look prettier.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Nested list items
by ikegami (Patriarch) on Sep 21, 2006 at 16:02 UTC | |
|
Re^2: Nested list items
by jdtoronto (Prior) on Sep 21, 2006 at 16:24 UTC |