lib/RichTextElement.rb in taskjuggler-0.0.6 vs lib/RichTextElement.rb in taskjuggler-0.0.7
- old
+ new
@@ -214,19 +214,18 @@
pre = @data.altText if @data.altText
when :ref
when :href
when :blockfunc
when :inlinefunc
- noChilds = true
checkHandler
pre = @richText.functionHandler(@data[0]).to_s(@data[1])
when :italic
when :bold
when :code
when :text
else
- raise TjException.new, "Unknown RichTextElement category #{@category}"
+ raise "Unknown RichTextElement category #{@category}"
end
pre + children_to_s + post
end
@@ -321,11 +320,11 @@
post = '</a>'
when :blockfunc
pre = "<blockfunc:#{@data[0]}"
if @data[1]
@data[1].keys.sort.each do |key|
- pre += " #{key}=\"#{@data[1][key]}\""
+ pre += " #{key}=\"#{@data[1][key].gsub(/"/, '\"')}\""
end
end
post = "/>"
when :inlinefunc
pre = "<inlinefunc:#{@data[0]}"
@@ -346,11 +345,11 @@
post = '</code>'
when :text
pre = '['
post = ']'
else
- raise TjException.new, "Unknown RichTextElement category #{@category}"
+ raise "Unknown RichTextElement category #{@category}"
end
out = ''
@children.each do |el|
if el.is_a?(RichTextElement)
@@ -423,18 +422,21 @@
when :numberlist4
XMLElement.new('ol')
when :numberitem4
XMLElement.new('li')
when :img
- el = XMLElement.new('img', 'src' => @data.fileName)
- el['alt'] = @data.altText if @data.altText
- if @data.verticalAlign
- el['style'] = "vertical-align:#{@data.verticalAlign}; "
- end
- el
+ htmlObject
when :ref
- XMLElement.new('a', 'href' => "#{@data}.html")
+ href = if @data.include?('#')
+ # If the @data includes a reference to an anchor, we put the
+ # anchor part after the .html extension.
+ pre, post = @data.split('#')
+ pre + '.html#' + post
+ else
+ @data + '.html'
+ end
+ XMLElement.new('a', 'href' => href)
when :href
a = XMLElement.new('a', 'href' => @data.to_s)
a['target'] = @richText.linkTarget if @richText.linkTarget
a
when :blockfunc
@@ -453,11 +455,11 @@
XMLElement.new('code', attrs)
when :text
noChilds = true
XMLText.new(@children[0])
else
- raise TjException.new, "Unknown RichTextElement category #{@category}"
+ raise "Unknown RichTextElement category #{@category}"
end
# Some elements never have leaves.
return html if noChilds
@@ -524,9 +526,30 @@
s += '.' unless s.empty?
s += "#{@data[i - 1]}"
end
s += ' '
el << XMLText.new(s)
+ end
+ el
+ end
+
+ def htmlObject
+ fileTypes = { 'png' => { 'type' => 'image/png' },
+ 'gif' => { 'type' => 'image/gif' },
+ 'jpg' => { 'type' => 'image/jpg' },
+ 'svg' => { 'type' => 'image/svg+xml', 'class' => 'img' }}
+ # Error checking must have been done in the parser!
+ # File types must be in sync with
+ # RichTextSyntaxRules::rule_plainTextWithLinks
+ return nil unless (index = @data.fileName.rindex('.'))
+ extension = @data.fileName[index + 1..-1].downcase
+ return nil unless (attributes = fileTypes[extension])
+ attributes['data'] = @data.fileName
+
+ el = XMLElement.new('object', attributes)
+ el['alt'] = @data.altText if @data.altText
+ if @data.verticalAlign
+ el['style'] = "vertical-align:#{@data.verticalAlign}; "
end
el
end
def textBlockFormat(indent, label, str, width)