Method: Docx::Elements::Containers::TextRun#to_html

Defined in:
lib/docx/containers/text_run.rb

#to_htmlObject

Return text as a HTML fragment with formatting based on properties.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/docx/containers/text_run.rb', line 61

def to_html
  html = @text
  html = html_tag(:em, content: html) if italicized?
  html = html_tag(:strong, content: html) if bolded?
  styles = {}
  styles['text-decoration'] = 'underline' if underlined?
  # No need to be granular with font size down to the span level if it doesn't vary.
  styles['font-size'] = "#{font_size}pt" if font_size != @font_size 
  html = html_tag(:span, content: html, styles: styles) unless styles.empty?
  return html
end