Class: Coradoc::Markdown::Serializer::Serializers::Verse

Inherits:
ElementSerializer show all
Defined in:
lib/coradoc/markdown/serializer/serializers/verse.rb

Overview

Verse: blockquote with hard line breaks preserved. The verse semantic is lost but line breaks survive.

Instance Method Summary collapse

Methods inherited from ElementSerializer

call, handles?, #handles?, handles_type, #handles_type

Instance Method Details

#call(element, _ctx) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/coradoc/markdown/serializer/serializers/verse.rb', line 14

def call(element, _ctx)
  body = element.content.to_s
  attribution = element.attribution
  citetitle = element.citetitle
  attribution_line = if attribution && citetitle
                       "\n>\n> — #{attribution}, <cite>#{citetitle}</cite>"
                     elsif attribution
                       "\n>\n> — #{attribution}"
                     else
                       ''
                     end
  body.lines.map { |line| "> #{line}".rstrip }.join("\n").concat(attribution_line)
end