class Parchment::TextRun
A “run” of text within a Paragraph
. Each run may have its own style attributes different from that of the Paragraph
. These are iterated through to generate a line of formatted output.
Attributes
Public Class Methods
new(paragraph, document)
click to toggle source
# File lib/parchment/text_run.rb, line 15 def initialize(paragraph, document) raise MissingFormatterMethodError unless @node @content = @node.content @default_font_size = paragraph.font_size end
Public Instance Methods
font_size()
click to toggle source
The font size of the TextRun
. Will return the Paragraph’s default font size if not defined.
# File lib/parchment/text_run.rb, line 24 def font_size @style.font_size || @default_font_size end
to_html()
click to toggle source
Return a HTML element String with formatting based on the TextRun’s properties.
# File lib/parchment/text_run.rb, line 45 def to_html html = @content html = html_tag(:em, content: html) if italic? html = html_tag(:strong, content: html) if bold? styles = {} styles['text-decoration'] = 'underline' if underline? # 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 != @default_font_size html = html_tag(:span, content: html, styles: styles) unless styles.empty? return html end
to_s()
click to toggle source
Output the unformatted TextRun’s content as a String.
# File lib/parchment/text_run.rb, line 37 def to_s @content end
Also aliased as: text