asciidoctor 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile +2 -0
  2. data/README.asciidoc +35 -26
  3. data/Rakefile +9 -6
  4. data/asciidoctor.gemspec +27 -8
  5. data/bin/asciidoctor +1 -1
  6. data/lib/asciidoctor.rb +351 -63
  7. data/lib/asciidoctor/abstract_block.rb +218 -0
  8. data/lib/asciidoctor/abstract_node.rb +249 -0
  9. data/lib/asciidoctor/attribute_list.rb +211 -0
  10. data/lib/asciidoctor/backends/base_template.rb +99 -0
  11. data/lib/asciidoctor/backends/docbook45.rb +510 -0
  12. data/lib/asciidoctor/backends/html5.rb +585 -0
  13. data/lib/asciidoctor/block.rb +27 -254
  14. data/lib/asciidoctor/callouts.rb +117 -0
  15. data/lib/asciidoctor/debug.rb +7 -4
  16. data/lib/asciidoctor/document.rb +229 -77
  17. data/lib/asciidoctor/inline.rb +29 -0
  18. data/lib/asciidoctor/lexer.rb +1330 -502
  19. data/lib/asciidoctor/list_item.rb +33 -34
  20. data/lib/asciidoctor/reader.rb +305 -142
  21. data/lib/asciidoctor/renderer.rb +115 -19
  22. data/lib/asciidoctor/section.rb +100 -189
  23. data/lib/asciidoctor/substituters.rb +468 -0
  24. data/lib/asciidoctor/table.rb +499 -0
  25. data/lib/asciidoctor/version.rb +1 -1
  26. data/test/attributes_test.rb +301 -87
  27. data/test/blocks_test.rb +568 -0
  28. data/test/document_test.rb +221 -24
  29. data/test/fixtures/dot.gif +0 -0
  30. data/test/fixtures/encoding.asciidoc +1 -0
  31. data/test/fixtures/include-file.asciidoc +1 -0
  32. data/test/fixtures/tip.gif +0 -0
  33. data/test/headers_test.rb +411 -43
  34. data/test/lexer_test.rb +265 -45
  35. data/test/links_test.rb +144 -3
  36. data/test/lists_test.rb +2252 -74
  37. data/test/paragraphs_test.rb +21 -30
  38. data/test/preamble_test.rb +24 -0
  39. data/test/reader_test.rb +248 -12
  40. data/test/renderer_test.rb +22 -0
  41. data/test/substitutions_test.rb +414 -0
  42. data/test/tables_test.rb +484 -0
  43. data/test/test_helper.rb +70 -6
  44. data/test/text_test.rb +30 -6
  45. metadata +64 -10
  46. data/lib/asciidoctor/render_templates.rb +0 -317
  47. data/lib/asciidoctor/string.rb +0 -12
@@ -0,0 +1,585 @@
1
+ class Asciidoctor::BaseTemplate
2
+
3
+ # create template matter to insert a style class from the role attribute if specified
4
+ def style_class
5
+ attrvalue(:role)
6
+ end
7
+ end
8
+
9
+ module Asciidoctor::HTML5
10
+ class DocumentTemplate < ::Asciidoctor::BaseTemplate
11
+ def render_outline(node, to_depth = 2)
12
+ toc_level = nil
13
+ sections = node.sections
14
+ unless sections.empty?
15
+ toc_level, indent = ''
16
+ unless node.is_a?(::Asciidoctor::Document)
17
+ indent = ' ' * (node.document.doctype == 'book' ? node.level + 1 : node.level)
18
+ end
19
+ toc_level << "#{indent}<ol>\n"
20
+ sections.each do |section|
21
+ toc_level << "#{indent} <li><a href=\"##{section.id}\">#{section.sectnum} #{section.title}</a></li>\n"
22
+ if section.level < to_depth && (child_toc_level = render_outline(section, to_depth))
23
+ toc_level << "#{indent} <li>\n#{child_toc_level}\n#{indent} </li>\n"
24
+ end
25
+ end
26
+ toc_level << "#{indent}</ol>"
27
+ end
28
+ toc_level
29
+ end
30
+
31
+ # Internal: Generate the default stylesheet for CodeRay
32
+ #
33
+ # returns the default CodeRay stylesheet as a String
34
+ def default_coderay_stylesheet
35
+ Asciidoctor.require_library 'coderay'
36
+ ::CodeRay::Encoders[:html]::CSS.new(:default).stylesheet
37
+ end
38
+
39
+ def template
40
+ @template ||= @eruby.new <<-EOS
41
+ <%#encoding:UTF-8%>
42
+ <!DOCTYPE html>
43
+ <html lang="en">
44
+ <head>
45
+ <meta http-equiv="Content-Type" content="text/html; charset=<%= attr :encoding %>">
46
+ <meta name="generator" content="Asciidoctor <%= attr 'asciidoctor-version' %>">
47
+ <% if attr? :description %><meta name="description" content="<%= attr :description %>"><% end %>
48
+ <% if attr? :keywords %><meta name="keywords" content="<%= attr :keywords %>"><% end %>
49
+ <title><%= doctitle %></title>
50
+ <% if attr? :toc %>
51
+ <style>
52
+ #toc > ol { padding-left: 0; }
53
+ #toc ol { list-style-type: none; }
54
+ </style>
55
+ <% end %>
56
+ <% unless attr(:stylesheet, '').empty? %>
57
+ <link rel="stylesheet" href="<%= File.join((attr :stylesdir, '.'), (attr :stylesheet)) %>">
58
+ <% end %>
59
+ <%
60
+ case attr 'source-highlighter' %><%
61
+ when 'coderay' %>
62
+ <style>
63
+ pre.highlight { border: none; background-color: #F8F8F8; }
64
+ pre.highlight code, pre.highlight pre { color: #333; }
65
+ pre.highlight span.line-numbers { display: inline-block; margin-right: 4px; padding: 1px 4px; }
66
+ pre.highlight .line-numbers { background-color: #D5F6F6; color: gray; }
67
+ pre.highlight .line-numbers pre { color: gray; }
68
+ <% if (attr 'coderay-css', 'class') == 'class' %><%= template.default_coderay_stylesheet %><% end %>
69
+ </style><%
70
+ when 'highlightjs' %>
71
+ <link rel="stylesheet" href="<%= (attr :highlightjsdir, 'http://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3') %>/styles/<%= (attr 'highlightjs-theme', 'default') %>.min.css">
72
+ <style>
73
+ pre code { background-color: #F8F8F8; padding: 0; }
74
+ </style>
75
+ <script src="<%= (attr :highlightjsdir, 'http://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3') %>/highlight.min.js"></script>
76
+ <script>hljs.initHighlightingOnLoad();</script>
77
+ <% end %>
78
+ </head>
79
+ <body#{attribute('id', :'css-signature')} class="<%= doctype %>"<% if attr? 'max-width' %> style="max-width: <%= attr 'max-width' %>;"<% end %>>
80
+ <% unless noheader %>
81
+ <div id="header">
82
+ <% if has_header? %>
83
+ <% unless notitle %>
84
+ <h1><%= header.title %></h1>
85
+ <% end %>
86
+ <% if attr? :author %><span id="author"><%= attr :author %></span><br><% end %>
87
+ <% if attr? :email %><span id="email" class="monospaced">&lt;<%= attr :email %>&gt;</span><br><% end %>
88
+ <% if attr? :revnumber %><span id="revnumber">version <%= attr :revnumber %><%= attr?(:revdate) ? ',' : '' %></span><% end %>
89
+ <% if attr? :revdate %><span id="revdate"><%= attr :revdate %></span><% end %>
90
+ <% if attr? :revremark %><br><span id="revremark"><%= attr :revremark %></span><% end %>
91
+ <% end %>
92
+ <% if attr? :toc %>
93
+ <div id="toc">
94
+ <div id="toctitle"><%= attr 'toc-title', 'Table of Contents' %></div>
95
+ <%= template.render_outline(self, (attr :toclevels, 2).to_i) %>
96
+ </div>
97
+ <% end %>
98
+ </div>
99
+ <% end %>
100
+ <div id="content">
101
+ <%= content %>
102
+ </div>
103
+ <div id="footer">
104
+ <div id="footer-text">
105
+ Last updated <%= attr :localdatetime %>
106
+ </div>
107
+ </div>
108
+ </body>
109
+ </html>
110
+ EOS
111
+ end
112
+ end
113
+
114
+ class EmbeddedTemplate < ::Asciidoctor::BaseTemplate
115
+ def template
116
+ @template ||= @eruby.new <<-EOS
117
+ <%#encoding:UTF-8%>
118
+ <%= content %>
119
+ EOS
120
+ end
121
+ end
122
+
123
+ class BlockPreambleTemplate < ::Asciidoctor::BaseTemplate
124
+ def template
125
+ @template ||= @eruby.new <<-EOS
126
+ <%#encoding:UTF-8%>
127
+ <div id="preamble">
128
+ <div class="sectionbody">
129
+ <%= content %>
130
+ </div>
131
+ </div>
132
+ EOS
133
+ end
134
+ end
135
+
136
+ class SectionTemplate < ::Asciidoctor::BaseTemplate
137
+ def template
138
+ @template ||= @eruby.new <<-EOS
139
+ <%#encoding:UTF-8%>
140
+ <% if level == 0 %>
141
+ <h1#{id}><%= title %></h1>
142
+ <%= content %>
143
+ <% else %>
144
+ <div class="sect<%= @level %>#{style_class}">
145
+ <h<%= @level + 1 %>#{id}><% if attr? :numbered %><%= sectnum %> <% end %><%= title %></h<%= @level + 1 %>>
146
+ <% if @level == 1 %>
147
+ <div class="sectionbody">
148
+ <%= content %>
149
+ </div>
150
+ <% else %>
151
+ <%= content %>
152
+ <% end %>
153
+ </div>
154
+ <% end %>
155
+ EOS
156
+ end
157
+ end
158
+
159
+ class BlockDlistTemplate < ::Asciidoctor::BaseTemplate
160
+ def template
161
+ @template ||= @eruby.new <<-EOS
162
+ <%#encoding:UTF-8%>
163
+ <div#{id} class="dlist#{style_class}">
164
+ <% if title %>
165
+ <div class="title"><%= title %></div>
166
+ <% end %>
167
+ <dl>
168
+ <% content.each do |dt, dd| %>
169
+ <dt class="hdlist1">
170
+ <%= dt.text %>
171
+ </dt>
172
+ <% unless dd.nil? %>
173
+ <dd>
174
+ <% if dd.text? %>
175
+ <p><%= dd.text %></p>
176
+ <% end %>
177
+ <% if dd.blocks? %>
178
+ <%= dd.content %>
179
+ <% end %>
180
+ </dd>
181
+ <% end %>
182
+ <% end %>
183
+ </dl>
184
+ </div>
185
+ EOS
186
+ end
187
+ end
188
+
189
+ class BlockListingTemplate < ::Asciidoctor::BaseTemplate
190
+ def template
191
+ @template ||= @eruby.new <<-EOS
192
+ <%#encoding:UTF-8%>
193
+ <div#{id} class="listingblock#{style_class}">
194
+ <% if title %>
195
+ <div class="title"><%= title %></div>
196
+ <% end %>
197
+ <div class="content monospaced">
198
+ <% if (attr :style) == 'source' %>
199
+ <pre class="highlight<% if attr('source-highlighter') == 'coderay' %> CodeRay<% end %>"><code#{attribute('class', :language)}><%= template.preserve_endlines(content, self) %></code></pre>
200
+ <% else %>
201
+ <pre><%= template.preserve_endlines(content, self) %></pre>
202
+ <% end %>
203
+ </div>
204
+ </div>
205
+ EOS
206
+ end
207
+ end
208
+
209
+ class BlockLiteralTemplate < ::Asciidoctor::BaseTemplate
210
+ def template
211
+ @template ||= @eruby.new <<-EOS
212
+ <%#encoding:UTF-8%>
213
+ <div#{id} class="literalblock#{style_class}">
214
+ <% if title %>
215
+ <div class="title"><%= title %></div>
216
+ <% end %>
217
+ <div class="content monospaced">
218
+ <pre><%= template.preserve_endlines(content, self) %></pre>
219
+ </div>
220
+ </div>
221
+ EOS
222
+ end
223
+ end
224
+
225
+ class BlockAdmonitionTemplate < ::Asciidoctor::BaseTemplate
226
+ def template
227
+ @template ||= @eruby.new <<-EOS
228
+ <%#encoding:UTF-8%>
229
+ <div#{id} class="admonitionblock#{style_class}">
230
+ <table>
231
+ <tr>
232
+ <td class="icon">
233
+ <% if attr? :icons %>
234
+ <img src="<%= icon_uri(attr :name) %>" alt="<%= attr :caption %>">
235
+ <% else %>
236
+ <div class="title"><%= attr :caption %></div>
237
+ <% end %>
238
+ </td>
239
+ <td class="content">
240
+ <% unless title.nil? %>
241
+ <div class="title"><%= title %></div>
242
+ <% end %>
243
+ <%= content %>
244
+ </td>
245
+ </tr>
246
+ </table>
247
+ </div>
248
+ EOS
249
+ end
250
+ end
251
+
252
+ class BlockParagraphTemplate < ::Asciidoctor::BaseTemplate
253
+ def template
254
+ @template ||= @eruby.new <<-EOS
255
+ <%#encoding:UTF-8%>
256
+ <div#{id} class="paragraph#{style_class}">
257
+ <% unless title.nil? %>
258
+ <div class="title"><%= title %></div>
259
+ <% end %>
260
+ <p><%= content %></p>
261
+ </div>
262
+ EOS
263
+ end
264
+ end
265
+
266
+ class BlockSidebarTemplate < ::Asciidoctor::BaseTemplate
267
+ def template
268
+ @template ||= @eruby.new <<-EOS
269
+ <%#encoding:UTF-8%>
270
+ <div#{id} class="sidebarblock#{style_class}">
271
+ <div class="content">
272
+ <% unless title.nil? %>
273
+ <div class="title"><%= title %></div>
274
+ <% end %>
275
+ <%= content %>
276
+ </div>
277
+ </div>
278
+ EOS
279
+ end
280
+ end
281
+
282
+ class BlockExampleTemplate < ::Asciidoctor::BaseTemplate
283
+ def template
284
+ @template ||= @eruby.new <<-EOS
285
+ <%#encoding:UTF-8%>
286
+ <div#{id} class="exampleblock#{style_class}">
287
+ <div class="content">
288
+ <% unless title.nil? %>
289
+ <div class="title"><%= title %></div>
290
+ <% end %>
291
+ <%= content %>
292
+ </div>
293
+ </div>
294
+ EOS
295
+ end
296
+ end
297
+
298
+ class BlockOpenTemplate < ::Asciidoctor::BaseTemplate
299
+ def template
300
+ @template ||= @eruby.new <<-EOS
301
+ <%#encoding:UTF-8%>
302
+ <div#{id} class="openblock#{style_class}">
303
+ <% unless title.nil? %>
304
+ <div class="title"><%= title %></div>
305
+ <% end %>
306
+ <div class="content">
307
+ <%= content %>
308
+ </div>
309
+ </div>
310
+ EOS
311
+ end
312
+ end
313
+
314
+ class BlockPassTemplate < ::Asciidoctor::BaseTemplate
315
+ def template
316
+ @template ||= @eruby.new <<-EOS
317
+ <%#encoding:UTF-8%>
318
+ <%= content %>
319
+ EOS
320
+ end
321
+ end
322
+
323
+ class BlockQuoteTemplate < ::Asciidoctor::BaseTemplate
324
+ def template
325
+ @template ||= @eruby.new <<-EOS
326
+ <%#encoding:UTF-8%>
327
+ <div#{id} class="quoteblock#{style_class}">
328
+ <% unless title.nil? %>
329
+ <div class="title"><%= title %></div>
330
+ <% end %>
331
+ <div class="content">
332
+ <%= content %>
333
+ </div>
334
+ <div class="attribution">
335
+ <% if attr? :citetitle %>
336
+ <em><%= attr :citetitle %></em>
337
+ <% end %>
338
+ <% if attr? :attribution %>
339
+ <% if attr? :citetitle %>
340
+ <br/>
341
+ <% end %>
342
+ <%= '&#8212; ' + attr(:attribution) %>
343
+ <% end %>
344
+ </div>
345
+ </div>
346
+ EOS
347
+ end
348
+ end
349
+
350
+ class BlockVerseTemplate < ::Asciidoctor::BaseTemplate
351
+ def template
352
+ @template ||= @eruby.new <<-EOS
353
+ <%#encoding:UTF-8%>
354
+ <div#{id} class="verseblock#{style_class}">
355
+ <% unless title.nil? %>
356
+ <div class="title"><%= title %></div>
357
+ <% end %>
358
+ <pre class="content"><%= template.preserve_endlines(content, self) %></pre>
359
+ <div class="attribution">
360
+ <% if attr? :citetitle %>
361
+ <em><%= attr :citetitle %></em>
362
+ <% end %>
363
+ <% if attr? :attribution %>
364
+ <% if attr? :citetitle %>
365
+ <br/>
366
+ <% end %>
367
+ <%= '&#8212; ' + attr(:attribution) %>
368
+ <% end %>
369
+ </div>
370
+ </div>
371
+ EOS
372
+ end
373
+ end
374
+
375
+ class BlockUlistTemplate < ::Asciidoctor::BaseTemplate
376
+ def template
377
+ @template ||= @eruby.new <<-EOS
378
+ <%#encoding:UTF-8%>
379
+ <div#{id} class="ulist#{attrvalue(:style)}#{style_class}">
380
+ <% unless title.nil? %>
381
+ <div class="title"><%= title %></div>
382
+ <% end %>
383
+ <ul>
384
+ <% content.each do |li| %>
385
+ <li>
386
+ <p><%= li.text %></p>
387
+ <% if li.blocks? %>
388
+ <%= li.content %>
389
+ <% end %>
390
+ </li>
391
+ <% end %>
392
+ </ul>
393
+ </div>
394
+ EOS
395
+ end
396
+ end
397
+
398
+ class BlockOlistTemplate < ::Asciidoctor::BaseTemplate
399
+ def template
400
+ @template ||= @eruby.new <<-EOS
401
+ <%#encoding:UTF-8%>
402
+ <div#{id} class="olist <%= attr :style %>#{style_class}">
403
+ <% unless title.nil? %>
404
+ <div class="title"><%= title %></div>
405
+ <% end %>
406
+ <ol class="<%= attr :style %>"#{attribute('start', :start)}>
407
+ <% content.each do |li| %>
408
+ <li>
409
+ <p><%= li.text %></p>
410
+ <% if li.blocks? %>
411
+ <%= li.content %>
412
+ <% end %>
413
+ </li>
414
+ <% end %>
415
+ </ol>
416
+ </div>
417
+ EOS
418
+ end
419
+ end
420
+
421
+ class BlockColistTemplate < ::Asciidoctor::BaseTemplate
422
+ def template
423
+ @template ||= @eruby.new <<-EOS
424
+ <%#encoding:UTF-8%>
425
+ <div#{id} class="colist <%= attr :style %>#{style_class}">
426
+ <% unless title.nil? %>
427
+ <div class="title"><%= title %></div>
428
+ <% end %>
429
+ <ol>
430
+ <% content.each do |li| %>
431
+ <li>
432
+ <p><%= li.text %></p>
433
+ </li>
434
+ <% end %>
435
+ </ol>
436
+ </div>
437
+ EOS
438
+ end
439
+ end
440
+
441
+ class BlockTableTemplate < ::Asciidoctor::BaseTemplate
442
+ def template
443
+ @template ||= @eruby.new <<-EOS
444
+ <%#encoding:UTF-8%>
445
+ <table#{id} class="tableblock frame-<%= attr :frame, 'all' %> grid-<%= attr :grid, 'all'%>#{style_class}" style="<%
446
+ if !(attr? 'autowidth-option') %>width: <%= attr :tablepcwidth %>%; <% end %><%
447
+ if attr? :float %>float: <%= attr :float %>; <% end %>">
448
+ <% if title? %>
449
+ <caption class="title"><%= title %></caption>
450
+ <% end %>
451
+ <% if (attr :rowcount) >= 0 %>
452
+ <colgroup>
453
+ <% if attr? 'autowidth-option' %>
454
+ <% @columns.each do |col| %>
455
+ <col>
456
+ <% end %>
457
+ <% else %>
458
+ <% @columns.each do |col| %>
459
+ <col style="width: <%= col.attr :colpcwidth %>%;">
460
+ <% end %>
461
+ <% end %>
462
+ </colgroup>
463
+ <% [:head, :foot, :body].select {|tsec| !rows[tsec].empty? }.each do |tsec| %>
464
+ <t<%= tsec %>>
465
+ <% @rows[tsec].each do |row| %>
466
+ <tr>
467
+ <% row.each do |cell| %>
468
+ <<%= tsec == :head ? 'th' : 'td' %> class="tableblock halign-<%= cell.attr :halign %> valign-<%= cell.attr :valign %>"#{attribute('colspan', 'cell.colspan')}#{attribute('rowspan', 'cell.rowspan')}><%
469
+ if tsec == :head %><%= cell.text %><% else %><%
470
+ case cell.attr(:style)
471
+ when :asciidoc %><div><%= cell.content %></div><%
472
+ when :verse %><div class="verse"><%= template.preserve_endlines(cell.text, self) %></div><%
473
+ when :literal %><div class="literal monospaced"><pre><%= template.preserve_endlines(cell.text, self) %></pre></div><%
474
+ when :header %><% cell.content.each do |text| %><p class="tableblock header"><%= text %></p><% end %><%
475
+ else %><% cell.content.each do |text| %><p class="tableblock"><%= text %></p><% end %><%
476
+ end %><% end %></<%= tsec == :head ? 'th' : 'td' %>>
477
+ <% end %>
478
+ </tr>
479
+ <% end %>
480
+ </t<%= tsec %>>
481
+ <% end %>
482
+ <% end %>
483
+ </table>
484
+ EOS
485
+ end
486
+ end
487
+
488
+ class BlockImageTemplate < ::Asciidoctor::BaseTemplate
489
+ def template
490
+ @template ||= @eruby.new <<-EOS
491
+ <%#encoding:UTF-8%>
492
+ <div#{id} class="imageblock#{style_class}">
493
+ <div class="content">
494
+ <% if attr :link %>
495
+ <a class="image" href="<%= attr :link %>"><img src="<%= image_uri(attr :target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}></a>
496
+ <% else %>
497
+ <img src="<%= image_uri(attr :target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}>
498
+ <% end %>
499
+ </div>
500
+ <% if title %>
501
+ <div class="title"><%= title %></div>
502
+ <% end %>
503
+ </div>
504
+ EOS
505
+ end
506
+ end
507
+
508
+ class BlockRulerTemplate < ::Asciidoctor::BaseTemplate
509
+ def template
510
+ @template ||= @eruby.new <<-EOS
511
+ <hr>
512
+ EOS
513
+ end
514
+ end
515
+
516
+ class InlineBreakTemplate < ::Asciidoctor::BaseTemplate
517
+ def template
518
+ @template ||= @eruby.new <<-EOS
519
+ <%= text %><br>
520
+ EOS
521
+ end
522
+ end
523
+
524
+ class InlineCalloutTemplate < ::Asciidoctor::BaseTemplate
525
+ def template
526
+ @template ||= @eruby.new <<-EOS
527
+ <b><%= text %></b>
528
+ EOS
529
+ end
530
+ end
531
+
532
+ class InlineQuotedTemplate < ::Asciidoctor::BaseTemplate
533
+ QUOTED_TAGS = {
534
+ :emphasis => ['<em>', '</em>'],
535
+ :strong => ['<strong>', '</strong>'],
536
+ :monospaced => ['<tt>', '</tt>'],
537
+ :superscript => ['<sup>', '</sup>'],
538
+ :subscript => ['<sub>', '</sub>'],
539
+ :double => [Asciidoctor::INTRINSICS['ldquo'], Asciidoctor::INTRINSICS['rdquo']],
540
+ :single => [Asciidoctor::INTRINSICS['lsquo'], Asciidoctor::INTRINSICS['rsquo']],
541
+ :none => ['', '']
542
+ }
543
+
544
+ def template
545
+ @template ||= @eruby.new <<-EOS
546
+ <% tags = template.class::QUOTED_TAGS[@type] %><%= tags.first %><%
547
+ if attr? :role %><span#{attribute('class', :role)}><%
548
+ end %><%= @text %><%
549
+ if attr? :role %></span><%
550
+ end %><%= tags.last %>
551
+ EOS
552
+ end
553
+ end
554
+
555
+ class InlineAnchorTemplate < ::Asciidoctor::BaseTemplate
556
+ def template
557
+ @template ||= @eruby.new <<-EOS
558
+ <%
559
+ if type == :xref
560
+ %><a href="#<%= @target %>"><%= @text || @document.references[:ids].fetch(@target, '[' + @target + ']') %></a><%
561
+ elsif @type == :ref
562
+ %><a id="<%= @target %>"></a><%
563
+ else
564
+ %><a href="<%= @target %>"><%= @text %></a><%
565
+ end
566
+ %>
567
+ EOS
568
+ end
569
+ end
570
+
571
+ class InlineImageTemplate < ::Asciidoctor::BaseTemplate
572
+ def template
573
+ # care is taken here to avoid a space inside the optional <a> tag
574
+ @template ||= @eruby.new <<-EOS
575
+ <span class="image#{style_class}">
576
+ <%
577
+ if attr :link %><a class="image" href="<%= attr :link %>"><%
578
+ end %><img src="<%= image_uri(target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}#{attribute('title', :title)}><%
579
+ if attr :link%></a><% end
580
+ %>
581
+ </span>
582
+ EOS
583
+ end
584
+ end
585
+ end