42 lines
754 B
Ruby
42 lines
754 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Repubmark
|
|
module Elems
|
|
class Text < Base
|
|
parents :Joint
|
|
|
|
def initialize(parent, str, bold: false, italic: false)
|
|
super parent
|
|
|
|
self.str = str
|
|
|
|
@bold = !!bold
|
|
@italic = !!italic
|
|
end
|
|
|
|
#################
|
|
# Basic methods #
|
|
#################
|
|
|
|
def word_count = count_words @str
|
|
|
|
def to_html = str_to_html
|
|
|
|
def to_gemtext = @str
|
|
|
|
private
|
|
|
|
def str=(str)
|
|
@str = String(str).split.join(' ').freeze
|
|
end
|
|
|
|
def str_to_html
|
|
result = @str
|
|
result = "<em>#{result}</em>" if @italic
|
|
result = "<strong>#{result}</strong>" if @bold
|
|
result.freeze
|
|
end
|
|
end
|
|
end
|
|
end
|