Class: HikiDoc::HTMLOutput

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

Direct Known Subclasses

PikiDoc::HTMLOutput

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of HTMLOutput.



546
547
548
549
# File 'lib/vendor/hikidoc.rb', line 546

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

Instance Method Details

#block_plugin(str) ⇒ Object



690
691
692
# File 'lib/vendor/hikidoc.rb', line 690

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

#block_preformatted(str, info) ⇒ Object



667
668
669
670
671
672
673
674
675
676
677
678
# File 'lib/vendor/hikidoc.rb', line 667

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
    end
  end
  preformatted(text(str))
end

#blockquote_closeObject



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

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

#blockquote_openObject



659
660
661
# File 'lib/vendor/hikidoc.rb', line 659

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

#container(_for = nil) ⇒ Object



559
560
561
562
563
564
565
566
# File 'lib/vendor/hikidoc.rb', line 559

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

#del(item) ⇒ Object



720
721
722
# File 'lib/vendor/hikidoc.rb', line 720

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

#dlist_closeObject



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

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

#dlist_item(dt, dd) ⇒ Object



615
616
617
618
619
620
621
622
623
624
625
# File 'lib/vendor/hikidoc.rb', line 615

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



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

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

#em(item) ⇒ Object



716
717
718
# File 'lib/vendor/hikidoc.rb', line 716

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

#escape_html(text) ⇒ Object



740
741
742
# File 'lib/vendor/hikidoc.rb', line 740

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

#escape_html_param(str) ⇒ Object

Utilities



736
737
738
# File 'lib/vendor/hikidoc.rb', line 736

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

#escape_quote(text) ⇒ Object



748
749
750
# File 'lib/vendor/hikidoc.rb', line 748

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

#finishObject



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

def finish
  @f.string
end

#headline(level, title) ⇒ Object

Procedures



572
573
574
# File 'lib/vendor/hikidoc.rb', line 572

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

#hruleObject



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

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

Functions



698
699
700
# File 'lib/vendor/hikidoc.rb', line 698

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


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

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



728
729
730
# File 'lib/vendor/hikidoc.rb', line 728

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

#list_beginObject



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

def list_begin
end

#list_close(type) ⇒ Object



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

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

#list_endObject



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

def list_end
  @f.puts
end

#list_open(type) ⇒ Object



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

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

#listitem(item) ⇒ Object



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

def listitem(item)
  @f.print item
end

#listitem_closeObject



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

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

#listitem_openObject



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

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

#paragraph(lines) ⇒ Object



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

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

#preformatted(str) ⇒ Object



680
681
682
683
684
# File 'lib/vendor/hikidoc.rb', line 680

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

#resetObject



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

def reset
  @f = StringIO.new
end

#strong(item) ⇒ Object



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

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

#table_closeObject



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

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

#table_data(item, rs, cs) ⇒ Object



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

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

#table_head(item, rs, cs) ⇒ Object



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

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

#table_openObject



627
628
629
# File 'lib/vendor/hikidoc.rb', line 627

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

#table_record_closeObject



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

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

#table_record_openObject



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

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

#text(str) ⇒ Object



724
725
726
# File 'lib/vendor/hikidoc.rb', line 724

def text(str)
  escape_html(str)
end

#unescape_html(text) ⇒ Object



744
745
746
# File 'lib/vendor/hikidoc.rb', line 744

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

#wiki_name(name) ⇒ Object



702
703
704
# File 'lib/vendor/hikidoc.rb', line 702

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