"
items_before = item.split('|')
items_after = []
items_before.each do |before|
items_after << self.generate_contents(before).gsub(" ", "")
end
s += items_after.join("#{tag}><#{tag}>")
line_index += 1
temp_item = ""
tag = "td style=\"#{style}\""
end
end
pcodes.each do |pcode|
s = s.sub("___dummy_pcodes___", pcode)
end
block = "
#{s}
"
end
def block_to_html(block)
case block
when /\A[\[]/
parsed_block = self.parse_inline(block)
block = self.inline_to_html(parsed_block)
when /(\A[{][{][{])/
parsed_block = self.parse_inline(block.gsub("{{{", "[").gsub("}}}", "]"))
block = self.inline_to_html(parsed_block)
when /^[!]/
len = block.length - block.gsub!(/^[!]*/, "").length + 2
s = generate_contents(block)
a_name = "#{@title_list.length + 1}_#{len}"
@title_list << [s, len, a_name]
block = "#{s}"
when /^[|][|][|]/
block = self.process_table_line(block)
when /^[|]/
s_arr = block.split("\n")
#s_arr.pop
s = ""
line_index = 0
s_arr.each do |item|
if line_index == 0
item = '
"
when /^[-]/
block = list(block.split("\n"))
when /^http[:][\/][\/]/
block = "#{block} "
when /^https[:][\/][\/]/
block = "#{block} "
else
block = self.inline_to_html_from_block(block)
block = block + " " unless block == ""
end
block
end
def list(s_arr)
s_arr << ""
list_arr = []
s = ""
s_arr.each do |item|
if item.length > 0 && item.index("--") == 0
list_arr << item[1..item.length-1]
elsif item.length > 0 && item.index("-") == 0
if list_arr.length > 0
child_list = list(list_arr)
list_arr = []
else
child_list = ""
end
line = generate_contents(item[1..item.length])
if !child_list.blank?
s += "#{child_list}
#{line}"
else
s += "
#{line}"
end
else
if list_arr.length > 0
child_list = list(list_arr)
s += "#{child_list}"
end
end
end
s = s + "
" if !s.blank?
s = generate_contents(s)
"
#{s}
".gsub(' ', '')
end
def inline_to_html(parsed_block)
command = parsed_block[0]
result = ''
case command
when 'link'
link = parsed_block[1]
title = parsed_block[1]
if parsed_block.length > 2
title = parsed_block[2..parsed_block.length-1].join(" ")
end
result = "" + title + ""
when "code"
text = parsed_block[1..parsed_block.length-1].join(" ")
result = "
" + text + "
"
#p parsed_block
when "pcode"
text = parsed_block[1..parsed_block.length-1].join(" ")
result = "
" + text + "
"
when "b"
url = parsed_block[1]
quote = parsed_block[2..parsed_block.length-1].join(" ")
result = "
"
when "image_url"
url = parsed_block[1]
result = ""
when "game"
id = parsed_block[1]
text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
text = text ? text.join(" ") : "ゲーム[ID:#{id}]"
url = "http://#{DOMAIN}/games/#{id}/play"
result = "#{text}"
when "open_game_form"
id = parsed_block[1]
text = parsed_block[2] ? parsed_block[2] : nil
submit_label = parsed_block[3] ? parsed_block[3..parsed_block.length-1] : nil
if text.blank?
text = "パラメータ"
end
if submit_label.blank?
submit_label = "ゲームを開く"
end
url = "http://#{DOMAIN}/games/#{id}/play"
result = <<-EOS
EOS
when "item"
id = parsed_block[1]
text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
text = text ? text.join(" ") : "素材/ゲームデータ[ID:#{id}]"
url = "http://#{DOMAIN}/published_items/#{id}"
result = "#{text}"
when "wiki"
text = parsed_block[1..parsed_block.length-1].join(" ")
url = "http://page.#{DOMAIN}/a/" + text
result = "#{text}"
when "jump_target"
text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
result = ""
when "jump"
link = parsed_block[1]
title = parsed_block[1]
if parsed_block.length > 2
title = parsed_block[2..parsed_block.length-1].join(" ")
end
result = "" + title + ""
when "strike"
text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
result = "#{text}"
when "bold"
text = parsed_block[1] ? parsed_block[1..parsed_block.length-1] : nil
result = "#{text}"
when "memo"
result = ""
when "font"
tags = parsed_block[1] ? parsed_block[1].split("_") : []
style = ""
tags.each do |tag|
if tag == "bold"
style += "font-weight:bold;"
elsif tag == "italic"
style += "font-style: italic;"
elsif tag == "strike"
style += "text-decoration:line-through;"
elsif ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"].include?(tag)
style += "font-size:#{tag};"
else
style += "color:#{tag};"
end
end
text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
result = "#{text}"
when "nicovideo"
id = parsed_block[1]
result = <<-EOS
EOS
when "youtube"
id = parsed_block[1]
result = <<-EOS
EOS
when "game_player"
id = parsed_block[1]
@wiki_module_game_embed ||= false
unless @wiki_module_game_embed
result = ""
@wiki_module_game_embed = true
else
text = parsed_block[2] ? parsed_block[2..parsed_block.length-1] : nil
text = text ? text.join(" ") : "ゲーム[ID:#{id}]"
url = "http://#{DOMAIN}/games/#{id}/play"
result = "#{text}"
end
else
result = execute_plugins(command, parsed_block)
if result
else
result = "[" + parsed_block.join(" ") + "]"
end
end
result
rescue => err
"
記述に間違いがあります: [" + parsed_block.join(" ") + "]
"
end
def execute_plugins(command, parsed_block)
result = false
@plugins ||= []
@plugins.each do |plugin|
if plugin.target?(command)
result = plugin.execute(command, parsed_block)
break
end
end
result
rescue => err
parsed_block << "{{プラグインのエラー}}"
end
def inline_to_html_from_block(block)
block.gsub!(/[\[].*?[\]]/) {|s|
s = self.inline_to_html(self.parse_inline(s))
}
block
end
def parse_inline(content)
content[1..content.length-2].sub(/([ ]|\n|\r\n|\r)/, " ").split(/[ ]/)
end
end