Class: HikiDoc::HTMLOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/hikidoc.rb

Instance Method Summary collapse

Constructor Details

#initialize(suffix = " />") ⇒ HTMLOutput

Returns a new instance of HTMLOutput.



550
551
552
553
# File 'lib/hikidoc.rb', line 550

def initialize(suffix = " />")
  @suffix = suffix
  @f = nil
end

Instance Method Details

#block_plugin(str) ⇒ Object



696
697
698
# File 'lib/hikidoc.rb', line 696

def block_plugin(str)
  @f.puts %Q(<div class="plugin">{{#{escape_html(str)}}}</div>)
end

#block_preformatted(str, info) ⇒ Object



671
672
673
674
675
676
677
678
679
680
681
682
683
684
# File 'lib/hikidoc.rb', line 671

def block_preformatted(str, info)
  syntax = info ? info.downcase : nil
  if syntax
    begin
      convertor = Syntax::Convertors::HTML.for_syntax(syntax)
      @f.puts convertor.convert(str)
      return
    rescue NameError, RuntimeError
      @f.puts %Q|<pre class="prettyprint">#{text(str)}</pre>|
      return
    end
  end
  preformatted(text(str))
end

#blockquote_closeObject



667
668
669
# File 'lib/hikidoc.rb', line 667

def blockquote_close
  @f.puts "</blockquote>"
end

#blockquote_openObject



663
664
665
# File 'lib/hikidoc.rb', line 663

def blockquote_open
  @f.print "<blockquote>"
end

#container(_for = nil) ⇒ Object



563
564
565
566
567
568
569
570
# File 'lib/hikidoc.rb', line 563

def container(_for=nil)
  case _for
  when :paragraph
    []
  else
    ""
  end
end

#del(item) ⇒ Object



726
727
728
# File 'lib/hikidoc.rb', line 726

def del(item)
  "<del>#{item}</del>"
end

#dlist_closeObject



615
616
617
# File 'lib/hikidoc.rb', line 615

def dlist_close
  @f.puts "</dl>"
end

#dlist_item(dt, dd) ⇒ Object



619
620
621
622
623
624
625
626
627
628
629
# File 'lib/hikidoc.rb', line 619

def dlist_item(dt, dd)
  case
  when dd.empty?
    @f.puts "<dt>#{dt}</dt>"
  when dt.empty?
    @f.puts "<dd>#{dd}</dd>"
  else
    @f.puts "<dt>#{dt}</dt>"
    @f.puts "<dd>#{dd}</dd>"
  end
end

#dlist_openObject



611
612
613
# File 'lib/hikidoc.rb', line 611

def dlist_open
  @f.puts "<dl>"
end

#em(item) ⇒ Object



722
723
724
# File 'lib/hikidoc.rb', line 722

def em(item)
  "<em>#{item}</em>"
end

#escape_html(text) ⇒ Object



750
751
752
# File 'lib/hikidoc.rb', line 750

def escape_html(text)
  text.gsub(/&/, "&amp;").gsub(/</, "&lt;").gsub(/>/, "&gt;")
end

#escape_html_param(str) ⇒ Object

Utilities



746
747
748
# File 'lib/hikidoc.rb', line 746

def escape_html_param(str)
  escape_quote(escape_html(str))
end

#escape_quote(text) ⇒ Object



758
759
760
# File 'lib/hikidoc.rb', line 758

def escape_quote(text)
  text.gsub(/"/, "&quot;")
end

#finishObject



559
560
561
# File 'lib/hikidoc.rb', line 559

def finish
  @f.string
end

#headline(level, title) ⇒ Object

Procedures



576
577
578
# File 'lib/hikidoc.rb', line 576

def headline(level, title)
  @f.puts "<h#{level}>#{title}</h#{level}>"
end

#hruleObject



580
581
582
# File 'lib/hikidoc.rb', line 580

def hrule
  @f.puts "<hr#{@suffix}"
end

Functions



704
705
706
# File 'lib/hikidoc.rb', line 704

def hyperlink(uri, title)
  %Q(<a href="#{escape_html_param(uri)}">#{title}</a>)
end


712
713
714
715
716
# File 'lib/hikidoc.rb', line 712

def image_hyperlink(uri, alt = nil)
  alt ||= uri.split(/\//).last
  alt = escape_html(alt)
  %Q(<img src="#{escape_html_param(uri)}" alt="#{alt}"#{@suffix})
end

#inline_plugin(src) ⇒ Object



738
739
740
# File 'lib/hikidoc.rb', line 738

def inline_plugin(src)
  %Q(<span class="plugin">{{#{escape_html(src)}}}</span>)
end

#list_beginObject



584
585
# File 'lib/hikidoc.rb', line 584

def list_begin
end

#list_close(type) ⇒ Object



595
596
597
# File 'lib/hikidoc.rb', line 595

def list_close(type)
  @f.print "</#{type}>"
end

#list_endObject



587
588
589
# File 'lib/hikidoc.rb', line 587

def list_end
  @f.puts
end

#list_open(type) ⇒ Object



591
592
593
# File 'lib/hikidoc.rb', line 591

def list_open(type)
  @f.puts "<#{type}>"
end

#listitem(item) ⇒ Object



607
608
609
# File 'lib/hikidoc.rb', line 607

def listitem(item)
  @f.print item
end

#listitem_closeObject



603
604
605
# File 'lib/hikidoc.rb', line 603

def listitem_close
  @f.puts "</li>"
end

#listitem_openObject



599
600
601
# File 'lib/hikidoc.rb', line 599

def listitem_open
  @f.print "<li>"
end

#paragraph(lines) ⇒ Object



692
693
694
# File 'lib/hikidoc.rb', line 692

def paragraph(lines)
  @f.puts "<p>#{lines.join("\n")}</p>"
end

#preformatted(str) ⇒ Object



686
687
688
689
690
# File 'lib/hikidoc.rb', line 686

def preformatted(str)
  @f.print "<pre>"
  @f.print str
  @f.puts "</pre>"
end

#resetObject



555
556
557
# File 'lib/hikidoc.rb', line 555

def reset
  @f = StringIO.new
end

#strong(item) ⇒ Object



718
719
720
# File 'lib/hikidoc.rb', line 718

def strong(item)
  "<strong>#{item}</strong>"
end

#table_closeObject



635
636
637
# File 'lib/hikidoc.rb', line 635

def table_close
  @f.puts "</table>"
end

#table_data(item, rs, cs) ⇒ Object



651
652
653
# File 'lib/hikidoc.rb', line 651

def table_data(item, rs, cs)
  @f.print "<td#{tdattr(rs, cs)}>#{item}</td>"
end

#table_head(item, rs, cs) ⇒ Object



647
648
649
# File 'lib/hikidoc.rb', line 647

def table_head(item, rs, cs)
  @f.print "<th#{tdattr(rs, cs)}>#{item}</th>"
end

#table_openObject



631
632
633
# File 'lib/hikidoc.rb', line 631

def table_open
  @f.puts %Q(<table border="1">)
end

#table_record_closeObject



643
644
645
# File 'lib/hikidoc.rb', line 643

def table_record_close
  @f.puts "</tr>"
end

#table_record_openObject



639
640
641
# File 'lib/hikidoc.rb', line 639

def table_record_open
  @f.print "<tr>"
end

#text(str) ⇒ Object



734
735
736
# File 'lib/hikidoc.rb', line 734

def text(str)
  escape_html(str)
end

#tt(item) ⇒ Object



730
731
732
# File 'lib/hikidoc.rb', line 730

def tt(item)
  "<tt>#{item}</tt>"
end

#unescape_html(text) ⇒ Object



754
755
756
# File 'lib/hikidoc.rb', line 754

def unescape_html(text)
  text.gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
end

#wiki_name(name) ⇒ Object



708
709
710
# File 'lib/hikidoc.rb', line 708

def wiki_name(name)
  hyperlink(name, text(name))
end