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)



246
247
248
249
250
251
252
253
254
# File 'lib/asciidoctor/latex/converter.rb', line 246

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.



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/asciidoctor/latex/converter.rb', line 175

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)
    else
      handle_default(node)
  end

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

- (Object) environment_literal(node)

method environment



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/asciidoctor/latex/converter.rb', line 208

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)



366
367
368
369
# File 'lib/asciidoctor/latex/converter.rb', line 366

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

- (Object) handle_chem(node)



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

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)



412
413
414
415
416
417
418
# File 'lib/asciidoctor/latex/converter.rb', line 412

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)



420
421
422
423
424
425
426
# File 'lib/asciidoctor/latex/converter.rb', line 420

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)



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/asciidoctor/latex/converter.rb', line 319

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)



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/asciidoctor/latex/converter.rb', line 350

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)



335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/asciidoctor/latex/converter.rb', line 335

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_jsxgraph(node)



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/asciidoctor/latex/converter.rb', line 381

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)



408
409
410
# File 'lib/asciidoctor/latex/converter.rb', line 408

def handle_null(node)

end

- (Object) handle_texmacro(node)

method environment_literal



241
242
243
244
# File 'lib/asciidoctor/latex/converter.rb', line 241

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

- (Object) info(node)



167
168
169
170
171
# File 'lib/asciidoctor/latex/converter.rb', line 167

def info node

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

end

- (Object) inline_anchor(node)



283
284
285
286
287
288
289
290
291
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 283

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)



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/asciidoctor/latex/converter.rb', line 256

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