1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Uv
  
  # def Uv.parse text, output = "xhtml", syntax_name = nil, line_numbers = false, render_style = "classic", headers = false
  #    init_syntaxes unless @syntaxes
  #    renderer = File.join( File.dirname(__FILE__), '..',"render", output,"#{render_style}.render")
  #    raise( ArgumentError, "Output for #{output} is not yet implemented" ) unless File.exists?(renderer)
  #    css_class = render_style
  #    render_options = YAML.load( File.open(  renderer ) )
  #    render_processor = SimpleRenderProcessor.new( render_options, line_numbers, headers )
  #    @syntaxes[syntax_name].parse( text,  render_processor )
  #    render_processor.string
  # end
  
  class RenderProcessor #< RenderProcessor
    
    def open_tag name, position
       @stack << name
       print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
       @position = position
       opt = options @stack
       print "<span class='#{name_to_class(name)}'>" unless name=~/punctuation/
    end
    
    def name_to_class(name)
      cl=""
      tags=name.split(".")
      (0..tags.length-1).each do |i|
        cl << tags[0..i].join("_")
        cl << " "
      end
      cl.strip
    end
    
    def close_tag name, position
       print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
       @position = position
       opt = options @stack
       print "</span>" unless name=~/punctuation/ #if opt
       @stack.pop
    end
    
    
  end
  
end