asciidoctor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of asciidoctor might be problematic. Click here for more details.

Files changed (40) hide show
  1. data/README.asciidoc +11 -2
  2. data/asciidoctor.gemspec +3 -2
  3. data/lib/asciidoctor.rb +95 -62
  4. data/lib/asciidoctor/abstract_block.rb +7 -5
  5. data/lib/asciidoctor/abstract_node.rb +63 -15
  6. data/lib/asciidoctor/attribute_list.rb +3 -1
  7. data/lib/asciidoctor/backends/base_template.rb +17 -7
  8. data/lib/asciidoctor/backends/docbook45.rb +182 -150
  9. data/lib/asciidoctor/backends/html5.rb +138 -110
  10. data/lib/asciidoctor/block.rb +21 -18
  11. data/lib/asciidoctor/callouts.rb +3 -1
  12. data/lib/asciidoctor/cli/invoker.rb +3 -3
  13. data/lib/asciidoctor/cli/options.rb +6 -6
  14. data/lib/asciidoctor/debug.rb +7 -6
  15. data/lib/asciidoctor/document.rb +197 -25
  16. data/lib/asciidoctor/errors.rb +1 -1
  17. data/lib/asciidoctor/helpers.rb +29 -0
  18. data/lib/asciidoctor/inline.rb +11 -4
  19. data/lib/asciidoctor/lexer.rb +338 -182
  20. data/lib/asciidoctor/list_item.rb +14 -12
  21. data/lib/asciidoctor/reader.rb +423 -206
  22. data/lib/asciidoctor/renderer.rb +59 -15
  23. data/lib/asciidoctor/section.rb +7 -4
  24. data/lib/asciidoctor/substituters.rb +536 -511
  25. data/lib/asciidoctor/table.rb +473 -472
  26. data/lib/asciidoctor/version.rb +1 -1
  27. data/man/asciidoctor.1 +23 -14
  28. data/man/asciidoctor.ad +13 -7
  29. data/test/attributes_test.rb +42 -8
  30. data/test/blocks_test.rb +161 -1
  31. data/test/document_test.rb +134 -16
  32. data/test/invoker_test.rb +14 -6
  33. data/test/lexer_test.rb +45 -18
  34. data/test/lists_test.rb +79 -0
  35. data/test/paragraphs_test.rb +9 -1
  36. data/test/reader_test.rb +456 -19
  37. data/test/sections_test.rb +19 -0
  38. data/test/substitutions_test.rb +14 -12
  39. data/test/tables_test.rb +10 -10
  40. metadata +3 -5
@@ -1,4 +1,5 @@
1
- class Asciidoctor::BaseTemplate
1
+ module Asciidoctor
2
+ class BaseTemplate
2
3
 
3
4
  # create template matter to insert a style class from the role attribute if specified
4
5
  def role_class
@@ -11,19 +12,19 @@ class Asciidoctor::BaseTemplate
11
12
  end
12
13
 
13
14
  def title_div(opts = {})
14
- %(<% if title? %><div class="title">#{opts.has_key?(:caption) ? '<% unless @caption.nil? %><%= @caption %><% end %>' : ''}<%= title %></div><% end %>)
15
+ %(<% if title? %><div class="title">#{opts.has_key?(:caption) ? '<%= @caption %>' : ''}<%= title %></div><% end %>)
15
16
  end
16
17
  end
17
18
 
18
- module Asciidoctor::HTML5
19
- class DocumentTemplate < ::Asciidoctor::BaseTemplate
20
- def render_outline(node, to_depth = 2)
19
+ module HTML5
20
+ class DocumentTemplate < BaseTemplate
21
+ def self.outline(node, to_depth = 2)
21
22
  toc_level = nil
22
23
  sections = node.sections
23
24
  unless sections.empty?
24
25
  toc_level, indent = ''
25
26
  nested = true
26
- unless node.is_a?(::Asciidoctor::Document)
27
+ unless node.is_a?(Document)
27
28
  if node.document.doctype == 'book'
28
29
  indent = ' ' * node.level unless node.level == 0
29
30
  nested = node.level > 0
@@ -34,7 +35,7 @@ class DocumentTemplate < ::Asciidoctor::BaseTemplate
34
35
  toc_level << "#{indent}<ol>\n" if nested
35
36
  sections.each do |section|
36
37
  toc_level << "#{indent} <li><a href=\"##{section.id}\">#{!section.special && section.level > 0 ? "#{section.sectnum} " : ''}#{section.attr('caption')}#{section.title}</a></li>\n"
37
- if section.level < to_depth && (child_toc_level = render_outline(section, to_depth))
38
+ if section.level < to_depth && (child_toc_level = outline(section, to_depth))
38
39
  if section.document.doctype != 'book' || section.level > 0
39
40
  toc_level << "#{indent} <li>\n#{child_toc_level}\n#{indent} </li>\n"
40
41
  else
@@ -50,15 +51,15 @@ class DocumentTemplate < ::Asciidoctor::BaseTemplate
50
51
  # Internal: Generate the default stylesheet for CodeRay
51
52
  #
52
53
  # returns the default CodeRay stylesheet as a String
53
- def default_coderay_stylesheet
54
- Asciidoctor.require_library 'coderay'
54
+ def self.default_coderay_stylesheet
55
+ Helpers.require_library 'coderay'
55
56
  ::CodeRay::Encoders[:html]::CSS.new(:default).stylesheet
56
57
  end
57
58
 
58
59
  def template
59
60
  @template ||= @eruby.new <<-EOS
60
61
  <%#encoding:UTF-8%><!DOCTYPE html>
61
- <html lang="en">
62
+ <html lang="<%= attr :lang, 'en' %>">
62
63
  <head>
63
64
  <meta http-equiv="Content-Type" content="text/html; charset=<%= attr :encoding %>">
64
65
  <meta name="generator" content="Asciidoctor <%= attr 'asciidoctor-version' %>">
@@ -72,7 +73,7 @@ class DocumentTemplate < ::Asciidoctor::BaseTemplate
72
73
  </style>
73
74
  <% end %>
74
75
  <% unless attr(:stylesheet, '').empty? %>
75
- <link rel="stylesheet" href="<%= File.join((attr :stylesdir, '.'), (attr :stylesheet)) %>">
76
+ <link rel="stylesheet" href="<%= (attr? :stylesdir) ? File.join((attr :stylesdir), (attr :stylesheet)) : (attr :stylesheet) %>">
76
77
  <% end %>
77
78
  <%
78
79
  case attr 'source-highlighter' %><%
@@ -83,7 +84,7 @@ pre.highlight code, pre.highlight pre { color: #333; }
83
84
  pre.highlight span.line-numbers { display: inline-block; margin-right: 4px; padding: 1px 4px; }
84
85
  pre.highlight .line-numbers { background-color: #D5F6F6; color: gray; }
85
86
  pre.highlight .line-numbers pre { color: gray; }
86
- <% if (attr 'coderay-css', 'class') == 'class' %><%= template.default_coderay_stylesheet %><% end %>
87
+ <% if (attr 'coderay-css', 'class') == 'class' %><%= template.class.default_coderay_stylesheet %><% end %>
87
88
  </style><%
88
89
  when 'highlightjs' %>
89
90
  <link rel="stylesheet" href="<%= (attr :highlightjsdir, 'http://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3') %>/styles/<%= (attr 'highlightjs-theme', 'default') %>.min.css">
@@ -91,15 +92,15 @@ pre.highlight .line-numbers pre { color: gray; }
91
92
  pre code { background-color: #F8F8F8; padding: 0; }
92
93
  </style>
93
94
  <script src="<%= (attr :highlightjsdir, 'http://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3') %>/highlight.min.js"></script>
94
- <script>hljs.initHighlightingOnLoad();</script>
95
+ <script>hljs.initHighlightingOnLoad()</script>
95
96
  <% end %>
96
97
  </head>
97
- <body#{attribute('id', :'css-signature')} class="<%= doctype %>"<% if attr? 'max-width' %> style="max-width: <%= attr 'max-width' %>;"<% end %>>
98
+ <body#{id} class="<%= doctype %>"<% if attr? 'max-width' %> style="max-width: <%= attr 'max-width' %>;"<% end %>>
98
99
  <% unless noheader %>
99
100
  <div id="header">
100
101
  <% if has_header? %>
101
102
  <% unless notitle %>
102
- <h1><%= header.title %></h1>
103
+ <h1><%= @header.title %></h1>
103
104
  <% end %>
104
105
  <% if attr? :author %><span id="author"><%= attr :author %></span><br><% end %>
105
106
  <% if attr? :email %><span id="email" class="monospaced">&lt;<%= attr :email %>&gt;</span><br><% end %>
@@ -109,8 +110,8 @@ pre code { background-color: #F8F8F8; padding: 0; }
109
110
  <% end %>
110
111
  <% if attr? :toc %>
111
112
  <div id="toc">
112
- <div id="toctitle"><%= attr 'toc-title', 'Table of Contents' %></div>
113
- <%= template.render_outline(self, (attr :toclevels, 2).to_i) %>
113
+ <div id="toctitle"><%= attr 'toc-title' %></div>
114
+ <%= template.class.outline(self, (attr :toclevels, 2).to_i) %>
114
115
  </div>
115
116
  <% end %>
116
117
  </div>
@@ -118,10 +119,10 @@ pre code { background-color: #F8F8F8; padding: 0; }
118
119
  <div id="content">
119
120
  <%= content %>
120
121
  </div>
121
- <% if !@references[:footnotes].empty? %>
122
+ <% if footnotes? %>
122
123
  <div id="footnotes">
123
124
  <hr>
124
- <% @references[:footnotes].each do |fn| %>
125
+ <% footnotes.each do |fn| %>
125
126
  <div class="footnote" id="_footnote_<%= fn.index %>">
126
127
  <a href="#_footnoteref_<%= fn.index %>"><%= fn.index %></a>. <%= fn.text %>
127
128
  </div>
@@ -140,15 +141,16 @@ pre code { background-color: #F8F8F8; padding: 0; }
140
141
  end
141
142
  end
142
143
 
143
- class EmbeddedTemplate < ::Asciidoctor::BaseTemplate
144
+ class EmbeddedTemplate < BaseTemplate
144
145
  def template
145
146
  @template ||= @eruby.new <<-EOS
146
- <%#encoding:UTF-8%><%= content %>
147
+ <%#encoding:UTF-8%><% unless notitle || !has_header? %><h1#{id}><%= header.title %></h1>
148
+ <% end %><%= content %>
147
149
  EOS
148
150
  end
149
151
  end
150
152
 
151
- class BlockPreambleTemplate < ::Asciidoctor::BaseTemplate
153
+ class BlockPreambleTemplate < BaseTemplate
152
154
  def template
153
155
  @template ||= @eruby.new <<-EOS
154
156
  <%#encoding:UTF-8%><div id="preamble">
@@ -160,7 +162,7 @@ class BlockPreambleTemplate < ::Asciidoctor::BaseTemplate
160
162
  end
161
163
  end
162
164
 
163
- class SectionTemplate < ::Asciidoctor::BaseTemplate
165
+ class SectionTemplate < BaseTemplate
164
166
  def template
165
167
  @template ||= @eruby.new <<-EOS
166
168
  <%#encoding:UTF-8%><%
@@ -169,7 +171,7 @@ if @level == 0 %>
169
171
  <%= content %>
170
172
  <% else %>
171
173
  <div class="sect<%= @level %>#{role_class}">
172
- <h<%= @level + 1 %>#{id}><% if !@special && (attr? :numbered) %><%= sectnum %> <% end %><%= attr :caption %><%= title %></h<%= @level + 1 %>>
174
+ <h<%= @level + 1 %>#{id}><% if !@special && (attr? :numbered) && @level < 4 %><%= sectnum %> <% end %><%= attr :caption %><%= title %></h<%= @level + 1 %>>
173
175
  <% if @level == 1 %>
174
176
  <div class="sectionbody">
175
177
  <%= content %>
@@ -183,7 +185,7 @@ if @level == 0 %>
183
185
  end
184
186
  end
185
187
 
186
- class BlockFloatingTitleTemplate < ::Asciidoctor::BaseTemplate
188
+ class BlockFloatingTitleTemplate < BaseTemplate
187
189
  def template
188
190
  @template ||= @eruby.new <<-EOS
189
191
  <%#encoding:UTF-8%><h<%= @level + 1 %>#{id} class="#{style_class false}#{role_class}"><%= title %></h<%= @level + 1 %>>
@@ -191,11 +193,11 @@ class BlockFloatingTitleTemplate < ::Asciidoctor::BaseTemplate
191
193
  end
192
194
  end
193
195
 
194
- class BlockDlistTemplate < ::Asciidoctor::BaseTemplate
196
+ class BlockDlistTemplate < BaseTemplate
195
197
  def template
196
198
  @template ||= @eruby.new <<-EOS
197
199
  <%#encoding:UTF-8%><%
198
- if (attr :style) == 'qanda' %>
200
+ if attr? :style, 'qanda' %>
199
201
  <div#{id} class="qlist#{style_class}#{role_class}">
200
202
  #{title_div}
201
203
  <ol>
@@ -214,7 +216,7 @@ if (attr :style) == 'qanda' %>
214
216
  <% end %>
215
217
  </ol>
216
218
  </div>
217
- <% elsif (attr :style) == 'horizontal' %>
219
+ <% elsif attr? :style, 'horizontal' %>
218
220
  <div#{id} class="hdlist#{role_class}">
219
221
  #{title_div}
220
222
  <table>
@@ -262,14 +264,14 @@ if (attr :style) == 'qanda' %>
262
264
  end
263
265
  end
264
266
 
265
- class BlockListingTemplate < ::Asciidoctor::BaseTemplate
267
+ class BlockListingTemplate < BaseTemplate
266
268
  def template
267
269
  @template ||= @eruby.new <<-EOS
268
270
  <%#encoding:UTF-8%><div#{id} class="listingblock#{role_class}">
269
- #{title_div}
271
+ #{title_div :caption => true}
270
272
  <div class="content monospaced">
271
- <% if (attr :style) == 'source' %>
272
- <pre class="highlight<% if attr('source-highlighter') == 'coderay' %> CodeRay<% end %>"><code#{attribute('class', :language)}><%= template.preserve_endlines(content, self) %></code></pre>
273
+ <% if attr? :style, 'source' %>
274
+ <pre class="highlight<% if attr? 'source-highlighter', 'coderay' %> CodeRay<% end %>"><code#{attribute('class', :language)}><%= template.preserve_endlines(content, self) %></code></pre>
273
275
  <% else %>
274
276
  <pre><%= template.preserve_endlines(content, self) %></pre>
275
277
  <% end %>
@@ -279,7 +281,7 @@ class BlockListingTemplate < ::Asciidoctor::BaseTemplate
279
281
  end
280
282
  end
281
283
 
282
- class BlockLiteralTemplate < ::Asciidoctor::BaseTemplate
284
+ class BlockLiteralTemplate < BaseTemplate
283
285
  def template
284
286
  @template ||= @eruby.new <<-EOS
285
287
  <%#encoding:UTF-8%><div#{id} class="literalblock#{role_class}">
@@ -292,7 +294,7 @@ class BlockLiteralTemplate < ::Asciidoctor::BaseTemplate
292
294
  end
293
295
  end
294
296
 
295
- class BlockAdmonitionTemplate < ::Asciidoctor::BaseTemplate
297
+ class BlockAdmonitionTemplate < BaseTemplate
296
298
  def template
297
299
  @template ||= @eruby.new <<-EOS
298
300
  <%#encoding:UTF-8%><div#{id} class="admonitionblock#{role_class}">
@@ -316,18 +318,23 @@ class BlockAdmonitionTemplate < ::Asciidoctor::BaseTemplate
316
318
  end
317
319
  end
318
320
 
319
- class BlockParagraphTemplate < ::Asciidoctor::BaseTemplate
321
+ class BlockParagraphTemplate < BaseTemplate
322
+ def paragraph(id, role, title, content)
323
+ %(<div#{id && " id=\"#{id}\""} class=\"paragraph#{role && " #{role}"}\">
324
+ #{title && "<div class=\"title\">#{title}</div>"}
325
+ <p>#{content}</p>
326
+ </div>)
327
+ end
328
+
320
329
  def template
330
+ # very hot piece of code, optimized for speed
321
331
  @template ||= @eruby.new <<-EOS
322
- <%#encoding:UTF-8%><div#{id} class="paragraph#{role_class}">
323
- #{title_div}
324
- <p><%= content %></p>
325
- </div>
332
+ <%#encoding:UTF-8%><%= template.paragraph(@id, (attr 'role'), title? ? title : nil, content) %>
326
333
  EOS
327
334
  end
328
335
  end
329
336
 
330
- class BlockSidebarTemplate < ::Asciidoctor::BaseTemplate
337
+ class BlockSidebarTemplate < BaseTemplate
331
338
  def template
332
339
  @template ||= @eruby.new <<-EOS
333
340
  <%#encoding:UTF-8%><div#{id} class="sidebarblock#{role_class}">
@@ -340,7 +347,7 @@ class BlockSidebarTemplate < ::Asciidoctor::BaseTemplate
340
347
  end
341
348
  end
342
349
 
343
- class BlockExampleTemplate < ::Asciidoctor::BaseTemplate
350
+ class BlockExampleTemplate < BaseTemplate
344
351
  def template
345
352
  @template ||= @eruby.new <<-EOS
346
353
  <%#encoding:UTF-8%><div#{id} class="exampleblock#{role_class}">
@@ -353,7 +360,7 @@ class BlockExampleTemplate < ::Asciidoctor::BaseTemplate
353
360
  end
354
361
  end
355
362
 
356
- class BlockOpenTemplate < ::Asciidoctor::BaseTemplate
363
+ class BlockOpenTemplate < BaseTemplate
357
364
  def template
358
365
  @template ||= @eruby.new <<-EOS
359
366
  <%#encoding:UTF-8%><div#{id} class="openblock#{role_class}">
@@ -366,15 +373,13 @@ class BlockOpenTemplate < ::Asciidoctor::BaseTemplate
366
373
  end
367
374
  end
368
375
 
369
- class BlockPassTemplate < ::Asciidoctor::BaseTemplate
376
+ class BlockPassTemplate < BaseTemplate
370
377
  def template
371
- @template ||= @eruby.new <<-EOS
372
- <%#encoding:UTF-8%><%= content %>
373
- EOS
378
+ :content
374
379
  end
375
380
  end
376
381
 
377
- class BlockQuoteTemplate < ::Asciidoctor::BaseTemplate
382
+ class BlockQuoteTemplate < BaseTemplate
378
383
  def template
379
384
  @template ||= @eruby.new <<-EOS
380
385
  <%#encoding:UTF-8%><div#{id} class="quoteblock#{role_class}">
@@ -388,9 +393,9 @@ class BlockQuoteTemplate < ::Asciidoctor::BaseTemplate
388
393
  <% end %>
389
394
  <% if attr? :attribution %>
390
395
  <% if attr? :citetitle %>
391
- <br/>
396
+ <br>
392
397
  <% end %>
393
- <%= '&#8212; ' + attr(:attribution) %>
398
+ <%= "&#8212; \#{attr :attribution}" %>
394
399
  <% end %>
395
400
  </div>
396
401
  </div>
@@ -398,7 +403,7 @@ class BlockQuoteTemplate < ::Asciidoctor::BaseTemplate
398
403
  end
399
404
  end
400
405
 
401
- class BlockVerseTemplate < ::Asciidoctor::BaseTemplate
406
+ class BlockVerseTemplate < BaseTemplate
402
407
  def template
403
408
  @template ||= @eruby.new <<-EOS
404
409
  <%#encoding:UTF-8%><div#{id} class="verseblock#{role_class}">
@@ -410,9 +415,9 @@ class BlockVerseTemplate < ::Asciidoctor::BaseTemplate
410
415
  <% end %>
411
416
  <% if attr? :attribution %>
412
417
  <% if attr? :citetitle %>
413
- <br/>
418
+ <br>
414
419
  <% end %>
415
- <%= '&#8212; ' + attr(:attribution) %>
420
+ <%= "&#8212; \#{attr :attribution}" %>
416
421
  <% end %>
417
422
  </div>
418
423
  </div>
@@ -420,17 +425,17 @@ class BlockVerseTemplate < ::Asciidoctor::BaseTemplate
420
425
  end
421
426
  end
422
427
 
423
- class BlockUlistTemplate < ::Asciidoctor::BaseTemplate
428
+ class BlockUlistTemplate < BaseTemplate
424
429
  def template
425
430
  @template ||= @eruby.new <<-EOS
426
431
  <%#encoding:UTF-8%><div#{id} class="ulist#{style_class}#{role_class}">
427
432
  #{title_div}
428
433
  <ul>
429
- <% content.each do |li| %>
434
+ <% content.each do |item| %>
430
435
  <li>
431
- <p><%= li.text %></p>
432
- <% if li.blocks? %>
433
- <%= li.content %>
436
+ <p><%= item.text %></p>
437
+ <% if item.blocks? %>
438
+ <%= item.content %>
434
439
  <% end %>
435
440
  </li>
436
441
  <% end %>
@@ -440,17 +445,17 @@ class BlockUlistTemplate < ::Asciidoctor::BaseTemplate
440
445
  end
441
446
  end
442
447
 
443
- class BlockOlistTemplate < ::Asciidoctor::BaseTemplate
448
+ class BlockOlistTemplate < BaseTemplate
444
449
  def template
445
450
  @template ||= @eruby.new <<-EOS
446
451
  <%#encoding:UTF-8%><div#{id} class="olist#{style_class}#{role_class}">
447
452
  #{title_div}
448
453
  <ol class="<%= attr :style %>"#{attribute('start', :start)}>
449
- <% content.each do |li| %>
454
+ <% content.each do |item| %>
450
455
  <li>
451
- <p><%= li.text %></p>
452
- <% if li.blocks? %>
453
- <%= li.content %>
456
+ <p><%= item.text %></p>
457
+ <% if item.blocks? %>
458
+ <%= item.content %>
454
459
  <% end %>
455
460
  </li>
456
461
  <% end %>
@@ -460,25 +465,25 @@ class BlockOlistTemplate < ::Asciidoctor::BaseTemplate
460
465
  end
461
466
  end
462
467
 
463
- class BlockColistTemplate < ::Asciidoctor::BaseTemplate
468
+ class BlockColistTemplate < BaseTemplate
464
469
  def template
465
470
  @template ||= @eruby.new <<-EOS
466
471
  <%#encoding:UTF-8%><div#{id} class="colist#{style_class}#{role_class}">
467
472
  #{title_div}
468
473
  <% if attr? :icons %>
469
474
  <table>
470
- <% content.each_with_index do |li, i| %>
475
+ <% content.each_with_index do |item, i| %>
471
476
  <tr>
472
477
  <td><img src="<%= icon_uri("callouts/\#{i + 1}") %>" alt="<%= i + 1 %>"></td>
473
- <td><%= li.text %></td>
474
- </tr>
478
+ <td><%= item.text %></td>
479
+ </tr>
475
480
  <% end %>
476
481
  </table>
477
482
  <% else %>
478
483
  <ol>
479
- <% content.each do |li| %>
484
+ <% content.each do |item| %>
480
485
  <li>
481
- <p><%= li.text %></p>
486
+ <p><%= item.text %></p>
482
487
  </li>
483
488
  <% end %>
484
489
  </ol>
@@ -488,7 +493,7 @@ class BlockColistTemplate < ::Asciidoctor::BaseTemplate
488
493
  end
489
494
  end
490
495
 
491
- class BlockTableTemplate < ::Asciidoctor::BaseTemplate
496
+ class BlockTableTemplate < BaseTemplate
492
497
  def template
493
498
  @template ||= @eruby.new <<-EOS
494
499
  <%#encoding:UTF-8%><table#{id} class="tableblock frame-<%= attr :frame, 'all' %> grid-<%= attr :grid, 'all'%>#{role_class}" style="<%
@@ -497,10 +502,10 @@ if attr? :float %>float: <%= attr :float %>; <% end %>">
497
502
  <% if title? %>
498
503
  <caption class="title"><% unless @caption.nil? %><%= @caption %><% end %><%= title %></caption>
499
504
  <% end %>
500
- <% if (attr :rowcount) >= 0 %>
505
+ <% if (attr :rowcount) >= 0 %>
501
506
  <colgroup>
502
507
  <% if attr? 'autowidth-option' %>
503
- <% @columns.each do |col| %>
508
+ <% @columns.each do %>
504
509
  <col>
505
510
  <% end %>
506
511
  <% else %>
@@ -509,7 +514,7 @@ if attr? :float %>float: <%= attr :float %>; <% end %>">
509
514
  <% end %>
510
515
  <% end %>
511
516
  </colgroup>
512
- <% [:head, :foot, :body].select {|tsec| !rows[tsec].empty? }.each do |tsec| %>
517
+ <% [:head, :foot, :body].select {|tsec| !@rows[tsec].empty? }.each do |tsec| %>
513
518
  <t<%= tsec %>>
514
519
  <% @rows[tsec].each do |row| %>
515
520
  <tr>
@@ -534,12 +539,14 @@ if attr? :float %>float: <%= attr :float %>; <% end %>">
534
539
  end
535
540
  end
536
541
 
537
- class BlockImageTemplate < ::Asciidoctor::BaseTemplate
542
+ class BlockImageTemplate < BaseTemplate
538
543
  def template
539
544
  @template ||= @eruby.new <<-EOS
540
- <%#encoding:UTF-8%><div#{id} class="imageblock#{role_class}">
545
+ <%#encoding:UTF-8%><div#{id} class="imageblock#{style_class}#{role_class}"<% if (attr? :align) || (attr? :float)
546
+ %> style="<% if attr? :align %>text-align: <%= attr :align %><% if attr? :float %>; <% end %><% end %><% if attr? :float %>float: <%= attr :float %><% end %>"<% end
547
+ %>>
541
548
  <div class="content">
542
- <% if attr :link %>
549
+ <% if attr? :link %>
543
550
  <a class="image" href="<%= attr :link %>"><img src="<%= image_uri(attr :target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}></a>
544
551
  <% else %>
545
552
  <img src="<%= image_uri(attr :target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}>
@@ -551,7 +558,7 @@ class BlockImageTemplate < ::Asciidoctor::BaseTemplate
551
558
  end
552
559
  end
553
560
 
554
- class BlockRulerTemplate < ::Asciidoctor::BaseTemplate
561
+ class BlockRulerTemplate < BaseTemplate
555
562
  def template
556
563
  @template ||= @eruby.new <<-EOS
557
564
  <%#encoding:UTF-8%><hr>
@@ -559,15 +566,23 @@ class BlockRulerTemplate < ::Asciidoctor::BaseTemplate
559
566
  end
560
567
  end
561
568
 
562
- class InlineBreakTemplate < ::Asciidoctor::BaseTemplate
569
+ class BlockPageBreakTemplate < BaseTemplate
570
+ def template
571
+ @template ||= @eruby.new <<-EOS
572
+ <%#encoding:UTF-8%><div style="page-break-after: always"></div>
573
+ EOS
574
+ end
575
+ end
576
+
577
+ class InlineBreakTemplate < BaseTemplate
563
578
  def template
564
579
  @template ||= @eruby.new <<-EOS
565
- <%#encoding:UTF-8%><%= text %><br>
580
+ <%#encoding:UTF-8%><%= "\#@text<br>" %>
566
581
  EOS
567
582
  end
568
583
  end
569
584
 
570
- class InlineCalloutTemplate < ::Asciidoctor::BaseTemplate
585
+ class InlineCalloutTemplate < BaseTemplate
571
586
  def template
572
587
  @template ||= @eruby.new <<-EOS
573
588
  <%#encoding:UTF-8%><% if attr? :icons %><img src="<%= icon_uri("callouts/\#@text") %>" alt="<%= @text %>"><% else %><b>&lt;<%= @text %>&gt;</b><% end %>
@@ -575,80 +590,93 @@ class InlineCalloutTemplate < ::Asciidoctor::BaseTemplate
575
590
  end
576
591
  end
577
592
 
578
- class InlineQuotedTemplate < ::Asciidoctor::BaseTemplate
593
+ class InlineQuotedTemplate < BaseTemplate
579
594
  QUOTED_TAGS = {
580
595
  :emphasis => ['<em>', '</em>'],
581
596
  :strong => ['<strong>', '</strong>'],
582
597
  :monospaced => ['<tt>', '</tt>'],
583
598
  :superscript => ['<sup>', '</sup>'],
584
599
  :subscript => ['<sub>', '</sub>'],
585
- :double => [Asciidoctor::INTRINSICS['ldquo'], Asciidoctor::INTRINSICS['rdquo']],
586
- :single => [Asciidoctor::INTRINSICS['lsquo'], Asciidoctor::INTRINSICS['rsquo']],
587
- :none => ['', '']
600
+ :double => ['&#8220;', '&#8221;'],
601
+ :single => ['&#8216;', '&#8217;']
602
+ #:none => ['', '']
588
603
  }
589
604
 
605
+ def quote(text, type, role)
606
+ start_tag, end_tag = QUOTED_TAGS[type] || ['', '']
607
+ if role
608
+ "#{start_tag}<span class=\"#{role}\">#{text}</span>#{end_tag}"
609
+ else
610
+ "#{start_tag}#{text}#{end_tag}"
611
+ end
612
+ end
613
+
590
614
  def template
615
+ # very hot piece of code, optimized for speed
591
616
  @template ||= @eruby.new <<-EOS
592
- <%#encoding:UTF-8%><% tags = template.class::QUOTED_TAGS[@type] %><%= tags.first %><%
593
- if attr? :role %><span#{attribute('class', :role)}><%
594
- end %><%= @text %><%
595
- if attr? :role %></span><%
596
- end %><%= tags.last %>
617
+ <%#encoding:UTF-8%><%= template.quote(@text, @type, attr('role')) %>
597
618
  EOS
598
619
  end
599
620
  end
600
621
 
601
- class InlineAnchorTemplate < ::Asciidoctor::BaseTemplate
622
+ class InlineAnchorTemplate < BaseTemplate
623
+ def anchor(target, text, type, document, window = nil)
624
+ case type
625
+ when :xref
626
+ text = document.references[:ids].fetch(target, "[#{target}]") if text.nil?
627
+ %(<a href="##{target}">#{text}</a>)
628
+ when :ref
629
+ %(<a id="#{target}"></a>)
630
+ when :bibref
631
+ %(<a id="#{target}"></a>[#{target}])
632
+ when :link
633
+ %(<a href="#{target}"#{window && " target=\"#{window}\""}>#{text}</a>)
634
+ end
635
+ end
636
+
602
637
  def template
638
+ # hot piece of code, optimized for speed
603
639
  @template ||= @eruby.new <<-EOS
604
- <%#encoding:UTF-8%><%
605
- if type == :xref
606
- %><a href="#<%= @target %>"><%= @text || @document.references[:ids].fetch(@target, '[' + @target + ']') %></a><%
607
- elsif @type == :ref
608
- %><a id="<%= @target %>"></a><%
609
- elsif @type == :bibref
610
- %><a id="<%= @target %>"></a>[<%= @target %>]<%
611
- else
612
- %><a href="<%= @target %>"><%= @text %></a><%
613
- end %>
640
+ <%#encoding:UTF-8%><%= template.anchor(@target, @text, @type, @document, @type == :link ? attr('window') : nil) %>
614
641
  EOS
615
642
  end
616
643
  end
617
644
 
618
- class InlineImageTemplate < ::Asciidoctor::BaseTemplate
645
+ class InlineImageTemplate < BaseTemplate
619
646
  def template
620
647
  # care is taken here to avoid a space inside the optional <a> tag
621
648
  @template ||= @eruby.new <<-EOS
622
649
  <%#encoding:UTF-8%><span class="image#{role_class}">
623
650
  <%
624
- if attr :link %><a class="image" href="<%= attr :link %>"><%
625
- end %><img src="<%= image_uri(target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}#{attribute('title', :title)}><%
626
- if attr :link%></a><% end
651
+ if attr? :link %><a class="image" href="<%= attr :link %>"><%
652
+ end %><img src="<%= image_uri(@target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}#{attribute('title', :title)}><%
653
+ if attr? :link%></a><% end
627
654
  %>
628
655
  </span>
629
656
  EOS
630
657
  end
631
658
  end
632
659
 
633
- class InlineFootnoteTemplate < ::Asciidoctor::BaseTemplate
660
+ class InlineFootnoteTemplate < BaseTemplate
634
661
  def template
635
662
  @template ||= @eruby.new <<-EOS
636
663
  <%#encoding:UTF-8%><%
637
- if type == :xref
638
- %><span class="footnoteref">[<a href="#_footnote_<%= attr :index %>" title="View footnote." class="footnote"><%= attr :index %></a>]</span><%
664
+ if @type == :xref
665
+ %><span class="footnoteref">[<a class="footnote" href="#_footnote_<%= attr :index %>" title="View footnote."><%= attr :index %></a>]</span><%
639
666
  else
640
- %><span class="footnote"<% if @id %> id="_footnote_<%= @id %>"<% end %>>[<a id="_footnoteref_<%= attr :index %>" href="#_footnote_<%= attr :index %>" title="View footnote." class="footnote"><%= attr :index %></a>]</span><%
667
+ %><span class="footnote"<% if @id %> id="_footnote_<%= @id %>"<% end %>>[<a id="_footnoteref_<%= attr :index %>" class="footnote" href="#_footnote_<%= attr :index %>" title="View footnote."><%= attr :index %></a>]</span><%
641
668
  end %>
642
669
  EOS
643
670
  end
644
671
  end
645
672
 
646
- class InlineIndextermTemplate < ::Asciidoctor::BaseTemplate
673
+ class InlineIndextermTemplate < BaseTemplate
647
674
  def template
648
675
  @template ||= @eruby.new <<-EOS
649
- <%#encoding:UTF-8%><% if type == :visible %><%= @text %><% end %>
676
+ <%#encoding:UTF-8%><%= "\#{@type == :visible ? @text : ''}" %>
650
677
  EOS
651
678
  end
652
679
  end
653
680
 
654
- end
681
+ end # module HTML5
682
+ end # module Asciidoctor