repubmark/lib/repubmark/elems/code_inline.rb

34 lines
618 B
Ruby

# frozen_string_literal: true
module Repubmark
module Elems
class CodeInline < Base
parents :Joint
def initialize(parent, str)
super parent
self.str = str
end
#################
# Basic methods #
#################
def to_html = "<code>#{CGI.escape_html(@str)}</code>".freeze
def to_gemtext = "«#{@str}»".freeze
private
def str=(str)
str = String(str).freeze
if str.include?("\n") || str.include?('«') || str.include?('»')
raise 'Invalid str'
end
@str = str
end
end
end
end