Class: Tefil::FswikiToMd
- Inherits:
-
TextFilterBase
- Object
- TextFilterBase
- Tefil::FswikiToMd
- Defined in:
- lib/tefil/fswikitomd.rb
Overview
! /usr/bin/env ruby coding: utf-8
Instance Method Summary collapse
-
#process_stream(in_io, out_io) ⇒ Object
def initialize(options) super(options) end.
Methods inherited from TextFilterBase
Constructor Details
This class inherits a constructor from Tefil::TextFilterBase
Instance Method Details
#process_stream(in_io, out_io) ⇒ Object
def initialize(options)
super()
end
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tefil/fswikitomd.rb', line 9 def process_stream(in_io, out_io) in_io.readlines.each do |line| # 行頭処理 case when line.sub!(/^!!!/ , '') then type = :head1 when line.sub!(/^!!/ , '') then type = :head2 when line.sub!(/^!/ , '') then type = :head3 when line.sub!(/^\*\*\*\*/ , '') then type = :item4 when line.sub!(/^\*\*\*/ , '') then type = :item3 when line.sub!(/^\*\*/ , '') then type = :item2 when line.sub!(/^\*/ , '') then type = :item1 when line.sub!(/^\+\+\+\+/ , '') then type = :enum4 when line.sub!(/^\+\+\+/ , '') then type = :enum3 when line.sub!(/^\+\+/ , '') then type = :enum2 when line.sub!(/^\+/ , '') then type = :enum1 when line.sub!(/^ / , '') then type = :pre when line.sub!(/^----/ , '') then type = :hline when line.sub!(/^\/\// , '') then type = :comment else type = :plain end # 行中要素の処理 line.gsub!(/\'\'\'/, '**') line.gsub!(/\'\'/, '*') if /\[(.*)\|(.*)\]/ =~ line # 複数ある場合は非対応。 str = $1 url = $2 line.sub!(/\[(.*)\|(.*)\]/, "[#{str}](#{url})") end case when type == :head1 then line.sub!(/^/, "#" ) when type == :head2 then line.sub!(/^/, "##" ) when type == :head3 then line.sub!(/^/, "###" ) when type == :item4 then line.sub!(/^/, " *" ) when type == :item3 then line.sub!(/^/, " *" ) when type == :item2 then line.sub!(/^/, " *" ) when type == :item1 then line.sub!(/^/, "*" ) when type == :enum4 then line.sub!(/^/, " 1.") when type == :enum3 then line.sub!(/^/, " 1." ) when type == :enum2 then line.sub!(/^/, " 1." ) when type == :enum1 then line.sub!(/^/, "1." ) when type == :pre then line.sub!(/^/, " " ) when type == :hline then line.sub!(/^/, "---" ) when type == :comment then line = "<!--#{line.chomp}-->" else # type == :pain then 'do nothing' end # 出力 out_io.print line #p "test" ## 空行処理 case when type == :head1 then out_io.puts when type == :head2 then out_io.puts when type == :head3 then out_io.puts else # type == :pain then 'do nothing' end end end |