Module: Asciidoctor::LaTeX::Html5ConverterExtensions

Included in:
Converter::Html5Converter
Defined in:
lib/asciidoctor/latex/converter.rb

Overview

code for Html5ConverterExtension & its insertion template by @mojavelinux

Constant Summary

ENV_CSS_OBLIQUE =
"+++<div class='click_oblique'>+++"
ENV_CSS_PLAIN =
"+++<div class='click_plain'>+++"
DIV_END =
'+++</div>+++'
TABLE_ROW_END =
'+++</tr></table>+++'

Instance Method Summary (collapse)

Instance Method Details

- (Object) click(node)



282
283
284
285
286
287
288
289
290
# File 'lib/asciidoctor/latex/converter.rb', line 282

def click node
  if node.attributes['plain-option']
    node.lines = [ENV_CSS_PLAIN] + node.lines + [DIV_END]
  else
    node.lines = [ENV_CSS_OBLIQUE] + node.lines + [DIV_END]
  end
  node.attributes['roles'] = (node.roles + ['click']) * ' '
  self.open node
end

- (Object) environment(node)

Dispatches a handler for the node (`NODE`) based on its role.



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/asciidoctor/latex/converter.rb', line 192

def environment node

  warn "entering environment(node)".red if $VERBOSE

  attrs = node.attributes

  warn "attrs['role'] = #{attrs['role']}".blue if $VERBOSE

  case attrs['role']
    when 'box', 'capsule'
      handle_null(node)
    when 'code'
      handle_code(node)
    when 'equation'
      handle_equation(node)
    when 'equationalign'
      handle_equation_align(node)
    when 'cd'
      handle_cd(node)
    when 'chem'
      handle_chem(node)
    when 'jsxgraph'
      handle_jsxgraph(node)
    when 'texmacro'
      handle_texmacro(node)
    when 'include_latex'
      handle_include_latex(node)
    else
      handle_default(node)
  end

  node.attributes['roles'] = (node.roles + ['environment']) * ' '
  self.open node
end

- (Object) environment_literal(node)

method environment



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/asciidoctor/latex/converter.rb', line 227

def environment_literal node

  warn "entering environment(node)".red if $VERBOSE

  attrs = node.attributes

  warn "attrs['role'] = #{attrs['role']}".blue if $VERBOSE

  case attrs['role']
    when 'box', 'capsule'
      handle_null(node)
    when 'code'
      handle_code(node)
    when 'equation'
      handle_equation_literal(node)
    when 'equationalign'
      handle_equation_align(node)
    when 'cd'
      handle_cd(node)
    when 'chem'
      handle_chem(node)
    when 'jsxgraph'
      handle_jsxgraph(node)
    when 'texmacro'
      handle_texmacro(node)
    else
      handle_default(node)
  end

  node.attributes['roles'] = (node.roles + ['environment']) * ' '
  self.open node
end

- (Object) handle_cd(node)



402
403
404
405
# File 'lib/asciidoctor/latex/converter.rb', line 402

def handle_cd(node)
  node.title = nil
  node.lines  = ['\\[', '\require{AMScd}', '\\begin{CD}', node.lines, '\\end{CD}', '\\]']
end

- (Object) handle_chem(node)



407
408
409
410
411
412
413
414
415
# File 'lib/asciidoctor/latex/converter.rb', line 407

def handle_chem(node)
  node.title = nil
  number_part = '<td class="equation_number_style">' + "(#{node.caption}) </td>"
  number_part = ["+++ #{number_part} +++"]
  equation_part = ['+++<td class="equation_content_style">+++'] + [' \\[\\ce{' + node.lines[0] + '}\\] '] + ['+++</td>+++']
  table_style='class="equation_table_style"'
  row_style='class="equation_row_style"'
  node.lines =  ["+++<table #{table_style}><tr #{row_style}>+++"]  + equation_part + number_part +['+++</tr></table>+++']
end

- (Object) handle_code(node)



448
449
450
451
452
453
454
# File 'lib/asciidoctor/latex/converter.rb', line 448

def handle_code(node)
  warn "handle code".red  if $VERBOSE
  if node.attributes['id'].nil?
    node.title = 'FOO'
    node.caption = '666'
  end
end

- (Object) handle_default(node)



456
457
458
459
460
461
462
# File 'lib/asciidoctor/latex/converter.rb', line 456

def handle_default(node)
    if node.attributes['plain-option']
      node.lines = [ENV_CSS_PLAIN] + node.lines + [DIV_END]
    else
      node.lines = [ENV_CSS_OBLIQUE] + node.lines + [DIV_END]
    end
end

- (Object) handle_equation(node)



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/asciidoctor/latex/converter.rb', line 355

def handle_equation(node)
  attrs = node.attributes
  options = attrs['options']
  node.title = nil
  number_part = '<td class="equation_number_style">' + "(#{node.caption}) </td>"
  number_part = ["+++ #{number_part} +++"]
  equation_part = ['+++<td class="equation_content_style";>+++'] + ['\\['] + node.lines + ['\\]'] + ['+++</td>+++']
  table_style='class="equation_table_style"'
  row_style='class="equation_row_style"'
  if options.include? 'numbered'
    node.lines =  ["+++<table #{table_style}><tr #{row_style}>+++"] + equation_part + number_part + [TABLE_ROW_END]
  else
    node.lines =  ["+++<table #{table_style}><tr #{row_style}>+++"] + equation_part + [TABLE_ROW_END]
  end
end

- (Object) handle_equation_align(node)



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/asciidoctor/latex/converter.rb', line 386

def handle_equation_align(node)
  attrs = node.attributes
  options = attrs['options']
  node.title = nil
  number_part = '<td class="equation_number_style">' + "(#{node.caption}) </td>"
  number_part = ["+++ #{number_part} +++"]
  equation_part = ['+++<td class="equation_content_style";>+++'] + ['\\[\\begin{split}'] + node.lines + ['\\end{split}\\]'] + ['+++</td>+++']
  table_style='class="equation_table_style" '
  row_style='class="equation_row_style"'
  if options.include? 'numbered'
    node.lines =  ["+++<table #{table_style}><tr #{row_style}>+++"] + equation_part + number_part + [TABLE_ROW_END]
  else
    node.lines =  ["+++<table #{table_style}><tr #{row_style}>+++"] + equation_part + [TABLE_ROW_END]
  end
end

- (Object) handle_equation_literal(node)



371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/asciidoctor/latex/converter.rb', line 371

def handle_equation_literal(node)
  attrs = node.attributes
  options = attrs['options']
  node.title = nil
  number_part = '<td class="equation_number_style">' + "(#{node.caption}) </td>"
  equation_part = ['<td class="equation_content_style";>'] + ['\\['] + node.lines + ['\\]'] + ['</td>']
  table_style='class="equation_table_style"'
  row_style='class="equation_row_style"'
  if options.include? 'numbered'
    node.lines =  ["<table #{table_style}><tr #{row_style}>"] + equation_part + number_part + ['</tr></table>']
  else
    node.lines =  ["<table #{table_style}><tr #{row_style}>"] + equation_part + ['</tr></table>']
  end
end

- (Object) handle_include_latex(node)

Example:

env.include_latex

– nput abc.text usepackagedef – Nothing appears in the HTML, bu lines nput abc.text usepackagedef appear in the generated tex file.



276
277
278
279
280
# File 'lib/asciidoctor/latex/converter.rb', line 276

def handle_include_latex node
  node.title = nil
  node.lines = [] # ["// "] + node.lines
  self.open node
end

- (Object) handle_jsxgraph(node)



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/asciidoctor/latex/converter.rb', line 417

def handle_jsxgraph(node)
  attrs = node.attributes
  if attrs['box'] == nil
    attrs['box'] = 'box'
  end
  if attrs['width'] == nil
    attrs['width'] = 450
  end
  if attrs['height'] == nil
    attrs['height'] = 450
  end
  line_array = ["\n+++\n"]
  # line_array += ["<link rel='stylesheet' type='text/css'  href='jsxgraph.css' />"]

  line_array += ["<link rel='stylesheet' type='text/css'  href='http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css' />"]
  line_array += ['<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.99.3/jsxgraphcore.js"></script>']
  line_array += ["<script src='http://jsxgraph.uni-bayreuth.de/distrib/GeonextReader.js' type='text/javascript'></script>"]
  line_array += ["<div id='#{attrs['box']}' class='jxgbox' style='width:" + "#{attrs['width']}" + "px; height:" + "#{attrs['height']}" +"px;'></div>"]
  line_array += ['<script type="text/javascript">']

  line_array += node.lines
  line_array += ['</script>']
  line_array += ['<br/>']
  line_array += ["\n+++\n"]
  node.lines = line_array
end

- (Object) handle_null(node)



444
445
446
# File 'lib/asciidoctor/latex/converter.rb', line 444

def handle_null(node)

end

- (Object) handle_texmacro(node)

method environment_literal



260
261
262
263
# File 'lib/asciidoctor/latex/converter.rb', line 260

def handle_texmacro node
  node.title = nil
  node.lines = ["+++\n\\("] + node.lines + ["\\)\n+++"]
end

- (Object) info(node)



184
185
186
187
188
# File 'lib/asciidoctor/latex/converter.rb', line 184

def info node

  warn "\n   HTMLConverter, node: #{node.node_name}".red if $VERBOSE

end

- (Object) inline_anchor(node)



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/asciidoctor/latex/converter.rb', line 319

def inline_anchor node

  case node.type.to_s

  when 'xref'
    refid = node.attributes['refid']
    if refid and refid[0] == '_'
      output = "<a href=\##{refid}>#{refid.gsub('_',' ')}</a>"
    else
      refs = node.parent.document.references[:ids]
      # FIXME: the next line is HACKISH (and it crashes the app when refs[refid]) is nil)
      # FIXME: and with the fix for nil results is even more hackish
      if refs[refid]
        reftext = refs[refid].gsub('.', '')
        reftext = reftext.gsub(/:.*/,'')
        if refid =~ /\Aeq-/
          output = "<span class='xref'><a href=\##{refid}>equation #{reftext}</a></span>"
        elsif refid =~ /\Aformula-/
          output = "<span class='xref'><a href=\##{refid}>formula #{reftext}</a></span>"
        elsif refid =~ /\Areaction-/
          output = "<span class='xref'><a href=\##{refid}>reaction #{reftext}</a></span>"
        else
          output = "<span class='xref'><a href=\##{refid}>#{reftext}</a></span>"
        end
      else
        output = old_inline_anchor node
      end
    end
  when 'link'
    output = "<a href=#{node.target}>#{node.text}</a>"
  else
    output =  old_inline_anchor node
  end
  output
end

- (Object) old_inline_anchor(node)



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/asciidoctor/latex/converter.rb', line 292

def old_inline_anchor node
  target = node.target
  case node.type
    when :xref
      refid = node.attributes['refid'] || target
      # NOTE we lookup text in converter because DocBook doesn't need this logic
      text = node.text || (node.document.references[:ids][refid] || %([#{refid}]))
      # FIXME shouldn't target be refid? logic seems confused here
      %(<a href="#{target}">#{text}</a>)
    when :ref
      %(<a id="#{target}"></a>)
    when :link
      attrs = []
      attrs << %( id="#{node.id}") if node.id
      if (role = node.role)
        attrs << %( class="#{role}")
      end
      attrs << %( title="#{node.attr 'title'}") if node.attr? 'title', nil, false
      attrs << %( target="#{node.attr 'window'}") if node.attr? 'window', nil, false
      %(<a href="#{target}"#{attrs.join}>#{node.text}</a>)
    when :bibref
      %(<a id="#{target}"></a>[#{target}])
    else
      warn %(asciidoctor: WARNING: unknown anchor type: #{node.type.inspect})
  end
end