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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# frozen_string_literal: true
require_relative 'spec_helper'
describe 'Asciidoctor::PDF::Converter - Open' do
it 'should be breakable by default', breakable: true do
with_content_spacer 10, 720 do |spacer_path|
pdf = to_pdf <<~EOS, analyze: true
image::#{spacer_path}[]
--
first page
second page
--
EOS
(expect pdf.pages).to have_size 2
(expect (pdf.find_unique_text 'first page')[:page_number]).to be 1
(expect (pdf.find_unique_text 'second page')[:page_number]).to be 2
end
end
it 'should keep block together when it has the unbreakable option', visual: true do
to_file = to_pdf_file <<~EOS, 'open-unbreakable-option-fit.pdf'
Make it rain.footnote:[money]
#{(['filler'] * 21).join %(\n\n)}
[%unbreakable]
--
To install Antora, open a terminal and type:
$ npm i -g @antora/cli@2.2 @antora/site-generator-default@2.2
The `@` at the beginning of the package name is important.
It tells `npm` that the `cli` package is located in the `antora` group.
If you omit this character, `npm` will assume the package name is the name of a git repository on GitHub.
The second `@` offsets the requested version number.footnote:[Clarification about this statement.]
Only the major and minor segments are specified to ensure you receive the latest patch update.
--
Make it snow.footnote:[dollar bills]
EOS
(expect to_file).to visually_match 'open-unbreakable-option-fit.pdf'
end
it 'should break an unbreakable block if it does not fit on one page', visual: true do
to_file = to_pdf_file <<~EOS, 'open-unbreakable-option-break.pdf'
Make it rain.footnote:[money]
#{(['filler'] * 21).join %(\n\n)}
[%unbreakable]
--
To install Antora, open a terminal and type:
$ npm i -g @antora/cli@2.2 @antora/site-generator-default@2.2
The `@` at the beginning of the package name is important.
It tells `npm` that the `cli` package is located in the `antora` group.
If you omit this character, `npm` will assume the package name is the name of a git repository on GitHub.
The second `@` offsets the requested version number.footnote:[Clarification about this statement.]
Only the major and minor segments are specified to ensure you receive the latest patch update.
#{(['filler inside open block'] * 25).join %(\n\n)}
--
Make it snow.footnote:[dollar bills]
EOS
(expect to_file).to visually_match 'open-unbreakable-option-break.pdf'
end
it 'should include title if specified' do
pdf = to_pdf <<~'EOS', analyze: true
.Title
--
content
--
EOS
title_texts = pdf.find_text 'Title'
(expect title_texts).to have_size 1
title_text = title_texts[0]
(expect title_text[:font_name]).to eql 'NotoSerif-Italic'
(expect title_text[:y]).to be > (pdf.find_unique_text 'content')[:y]
end
it 'should keep title with content if content is advanced to new page' do
pdf = with_content_spacer 10, 700 do |spacer_path|
to_pdf <<~EOS, analyze: true
image::#{spacer_path}[]
.Title
[%unbreakable]
--
content
more content
--
EOS
end
(expect pdf.pages).to have_size 2
(expect (pdf.find_unique_text 'content')[:page_number]).to be 2
(expect (pdf.find_unique_text 'Title')[:page_number]).to be 2
end
it 'should not dry run block unless necessary' do
calls = []
extensions = proc do
block :spy do
on_context :paragraph
process do |parent, reader, attrs|
block = create_paragraph parent, reader.lines, attrs
block.instance_variable_set :@_calls, calls
block.extend (Module.new do
def content
@_calls << (caller.join ?\n) if document.converter.scratch? # rubocop:disable RSpec/InstanceVariable
super
end
end)
end
end
end
{
'' => false,
%(.title) => false,
%([#idname]) => false,
%([%unbreakable]) => false,
%(before\n) => false,
%(before\n\n.title) => true,
%(before\n\n[#idname]) => true,
%(before\n\n[%unbreakable]) => true,
}.each do |before_block, dry_run|
input = <<~EOS.lstrip
#{before_block}
--
#{['block content'] * 4 * %(\n\n)}
[spy]
block content
--
EOS
pdf = to_pdf input, extensions: extensions, analyze: true
(expect pdf.pages).to have_size 1
(expect (pdf.find_text 'block content')[0][:page_number]).to be 1
if dry_run
(expect calls).not_to be_empty
else
(expect calls).to be_empty
end
end
end
end
|