Class: Coradoc::AsciiDoc::Serializer::Serializers::Paragraph

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/asciidoc/serializer/serializers/paragraph.rb

Overview

Serializer for Paragraph models

Instance Method Summary collapse

Methods inherited from Base

#serialize

Instance Method Details

#to_adoc(model, options_or_context = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/coradoc/asciidoc/serializer/serializers/paragraph.rb', line 9

def to_adoc(model, options_or_context = {})
  context = normalize_context(options_or_context)

  _title = model.title.nil? ? '' : ".#{serialize_child(model.title, context)}\n"
  _anchor = gen_anchor(model, context)
  attrs = if model.attributes.nil? || model.attributes.empty?
            ''
          else
            "#{AdocSerializer.serialize(
              model.attributes, context
            )}\n"
          end

  result = if model.tdsinglepara
             "#{_title}#{_anchor}" <<
               serialize_content(model.content)
           else
             "#{_title}#{_anchor}#{attrs}" <<
               serialize_content(model.content)
           end

  # Ensure paragraph ends with blank line for proper separation
  # unless this is the last element in a document (determined by context)
  # But not for tdsinglepara (table cell single paragraph)
  unless model.tdsinglepara || context.last_element
    if model.trailing_newlines.nil?
      # Semantic mode: Use default "\n\n" ending
      result = "#{result.chomp}\n\n" unless result.end_with?("\n\n")
    else
      # Exact mode: Use captured trailing newlines from original
      result += model.trailing_newlines
    end
  end

  result
end