Class: Coradoc::AsciiDoc::Model::TextElement

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/asciidoc/model/text_element.rb

Instance Attribute Summary

Attributes inherited from Base

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#block_level?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit

Class Method Details

.escape_keychars(string) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 21

def self.escape_keychars(string)
  subs = { '*' => '\*', '_' => '\_' }
  string
    .gsub(/((?<=\s)[*_]+)|[*_]+(?=\s)/) do |n|
    n.chars.map do |char|
      subs[char]
    end.join
  end
end

Instance Method Details

#inline?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 7

def inline?
  true
end

#textString

Alias for text to work with ContentList

Returns:

  • (String)

    The text content



60
61
62
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 60

def text
  to_s
end

#to_sString

Get text content as string

Returns:

  • (String)

    The text content



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 35

def to_s
  case content
  when String
    content
  when Array
    content.map(&:to_s).join
  when Coradoc::AsciiDoc::Model::Base
    content.to_adoc
  when Lutaml::Model::Serializable
    if content.class.attributes.key?(:content)
      content.content.to_s
    else
      ''
    end
  when nil
    ''
  else
    content.is_a?(String) ? content.to_s : ''
  end
end