Class: Coradoc::AsciiDoc::Model::TextElement
- Inherits:
-
Base
- Object
- Lutaml::Model::Serializable
- Base
- Coradoc::AsciiDoc::Model::TextElement
- Defined in:
- lib/coradoc/asciidoc/model/text_element.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#hard_break? ⇒ Boolean
Semantic predicates over the line-break marker.
- #inline? ⇒ Boolean
- #soft_break? ⇒ Boolean
-
#text ⇒ String
Alias for text to work with ContentList.
-
#to_s ⇒ String
Get text content as a string.
Methods inherited from Base
#block_level?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit
Class Method Details
.escape_keychars(string) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 43 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
#hard_break? ⇒ Boolean
Semantic predicates over the line-break marker. Consumers (the transformer, the serializer) call these instead of comparing line_break against literal strings, so the wire format for hard breaks is owned by the model layer (SRP).
35 36 37 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 35 def hard_break? line_break == LineBreakMarker::HARD end |
#inline? ⇒ Boolean
17 18 19 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 17 def inline? true end |
#soft_break? ⇒ Boolean
39 40 41 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 39 def soft_break? line_break.to_s.empty? end |
#text ⇒ String
Alias for text to work with ContentList
87 88 89 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 87 def text to_s end |
#to_s ⇒ String
Get text content as a string. Handles the polymorphic shape of
content (String, Array of mixed String/Model elements, nested
Serializable). When the content is an Array, each element is
rendered via its canonical source representation — Model::Base
elements go through to_adoc, Strings pass through unchanged —
so a downstream re-parse (e.g. by ToCoreModel.parse_inline_text)
sees the original inline-mark syntax rather than #<…> dumps.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 62 def to_s case content when String content when Array content.map { |element| element_to_s(element) }.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 |