lib/RichTextElement.rb in taskjuggler-0.0.2 vs lib/RichTextElement.rb in taskjuggler-0.0.3
- old
+ new
@@ -160,10 +160,11 @@
when :numberitem3
pre = "#{@data[0]}.#{@data[1]}.#{@data[2]} "
post = "\n\n"
when :ref
when :href
+ when :blockfunc
when :italic
when :bold
when :code
when :text
else
@@ -241,10 +242,18 @@
pre = "<ref data=\"#{@data}\">"
post = '</ref>'
when :href
pre = "<a href=\"#{@data}\" target=\"_blank\">"
post = '</a>'
+ when :blockfunc
+ pre = "<blockfunc:#{@data[0]}"
+ if @data[1]
+ @data[1].keys.sort.each do |key|
+ pre += " #{key}=\"#{@data[1][key]}\""
+ end
+ end
+ post = "/>"
when :italic
pre = '<i>'
post = '</i>'
when :bold
pre = '<b>'
@@ -271,10 +280,11 @@
pre + out + post
end
# Convert the intermediate representation into HTML elements.
def to_html
+ noChilds = false
html =
case @category
when :richtext
XMLElement.new('div')
when :title1
@@ -294,14 +304,16 @@
if @richText.sectionNumbers
el << XMLText.new("#{@data[0]}.#{@data[1]}.#{@data[2]} ")
end
el
when :hline
+ noChilds = true
XMLElement.new('hr')
when :paragraph
XMLElement.new('p')
when :pre
+ noChilds = true
pre = XMLElement.new('pre')
pre << XMLText.new(@children[0])
when :bulletlist1
XMLElement.new('ul')
when :bulletitem1
@@ -325,36 +337,30 @@
when :numberlist3
XMLElement.new('ol')
when :numberitem3
XMLElement.new('li')
when :ref
- if @data.include?(':')
- protocol, path = @data.split(':')
- raise TjException.new, "Reference protocol empty." if protocol.empty?
- if path.empty?
- raise TjException.new, "Reference path may not be empty."
- end
- args = children_to_s.split(' ')
- return @richText.protocolHandler(protocol).to_html(path, args)
- else
- XMLElement.new('a', 'href' => "#{@data}.html")
- end
+ XMLElement.new('a', 'href' => "#{@data}.html")
when :href
XMLElement.new('a', 'href' => @data, 'target' => '_blank')
+ when :blockfunc
+ noChilds = true
+ @richText.protocolHandler(@data[0]).to_html(@data[1])
when :italic
XMLElement.new('i')
when :bold
XMLElement.new('b')
when :code
XMLElement.new('code')
when :text
+ noChilds = true
XMLText.new(@children[0])
else
raise TjException.new, "Unknown RichTextElement category #{@category}"
end
# Some elements never have leaves.
- return html if [ :text, :pre, :hline ].include?(@category)
+ return html if noChilds
@children.each do |el_i|
html << el_i.to_html
html << XMLText.new(' ') if el_i.appendSpace
end