forked from admin-shell-io/aas-specs-antora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extended.rb
27 lines (23 loc) · 951 Bytes
/
extended.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This file is taken from the extension examples from the asciidoctor-pdf repository.
# https://github.com/asciidoctor/asciidoctor-pdf/blob/main/docs/modules/extend/examples/pdf-converter-numbered-paragraphs.rb
class PDFConverterNumberedParagraphs < (Asciidoctor::Converter.for 'pdf')
register_for 'pdf'
def init_pdf doc
doc
.find_by(context: :paragraph) {|candidate| [:document, :section].include? candidate.parent.context }
.each_with_index {|paragraph, idx| paragraph.set_attr 'number', idx + 1 }
super
end
def convert_paragraph node
if (paragraph_number = node.attr 'number')
float do
label = %(#{paragraph_number}.#{::Prawn::Text::NBSP})
label_width = rendered_width_of_string label
bounding_box [-label_width, cursor], width: label_width do
ink_prose label, color: 'CCCCCC', align: :right, margin: 0, single_line: true
end
end
end
super
end
end