In article <f7dffd10610080346r1858987fte6dae7a99e9acb3c@...>,
"TADA Tadashi" <sho@...> writes:
> ふぅむ。tDiary的には通ってもなんの問題もないんですが、HikiDoc的
> にはどうなんですかね。Hikiではこれが通ったら困る気がしますけど。
あぁ、なるほど。tDiary と Hiki ではプラグインの syntax が違
うんですね。
とすると、syntax を検査する部分をオプションで指定できるよう
にして、以下のようなのはどうでしょう。
Index: tdiary/hikidoc.rb
===================================================================
RCS file: /cvsroot/tdiary/core/tdiary/hikidoc.rb,v
retrieving revision 1.19
diff -u -p -r1.19 hikidoc.rb
--- tdiary/hikidoc.rb 5 Aug 2006 05:45:55 -0000 1.19
+++ tdiary/hikidoc.rb 9 Oct 2006 03:40:51 -0000
@@ -35,6 +35,7 @@ class HikiDoc < String
def initialize( content = '', options = {} )
@level = options[:level] || 1
@empty_element_suffix = options[:empty_element_suffix] || ' />'
+ @plugin_syntax = options[:plugin_syntax] || method(:valid_plugin_syntax?)
super( content )
end
@@ -89,6 +90,10 @@ class HikiDoc < String
PLUGIN_CLOSE = '}}'
PLUGIN_SPLIT_RE = /(#{Regexp.union( PLUGIN_OPEN, PLUGIN_CLOSE )})/
+ def valid_plugin_syntax?(code)
+ /['"]/ !~ code.gsub( /(['"]).*?\1/m, '' )
+ end
+
def parse_plugin( text )
ret = ''
plugin = false
@@ -96,15 +101,21 @@ class HikiDoc < String
text.split( PLUGIN_SPLIT_RE ).each do |str|
case str
when PLUGIN_OPEN
- plugin = true
- plugin_str += str
+ if !plugin
+ plugin = true
+ plugin_str = ''
+ else
+ plugin_str += str
+ end
when PLUGIN_CLOSE
if plugin
- plugin_str += str
- unless /['"]/ =~ plugin_str.gsub( /(['"]).*?\1/m, '' )
+ unescaped_plugin_str = unescape_meta_char(plugin_str, true)
+ if @plugin_syntax.call(CGI.unescapeHTML(unescaped_plugin_str))
+ ret << store_plugin_block("#{PLUGIN_OPEN}#{unescaped_plugin_str}#{PLUGIN_CLOSE}")
plugin = false
- ret << store_plugin_block( unescape_meta_char( plugin_str, true ) )
plugin_str = ''
+ else
+ plugin_str += str
end
else
ret << str
@@ -117,7 +128,7 @@ class HikiDoc < String
end
end
end
- ret << plugin_str if plugin
+ ret << PLUGIN_OPEN << plugin_str if plugin
ret
end
Index: tdiary/wiki_style.rb
===================================================================
RCS file: /cvsroot/tdiary/core/tdiary/wiki_style.rb,v
retrieving revision 1.20
diff -u -p -r1.20 wiki_style.rb
--- tdiary/wiki_style.rb 16 Aug 2006 03:28:00 -0000 1.20
+++ tdiary/wiki_style.rb 9 Oct 2006 03:40:51 -0000
@@ -107,13 +107,22 @@ module TDiary
end
private
+ def valid_plugin_syntax?(code)
+ eval( "BEGIN {return true}\n#{code}", nil, "(plugin)", 0 )
+ rescue SyntaxError
+ false
+ end
+
def to_html( string )
- html = HikiDoc::new( string, :level => 3, :empty_element_suffix => '>' ).to_html.strip
+ html = HikiDoc::new( string,
+ :level => 3,
+ :empty_element_suffix => '>',
+ :plugin_syntax => method(:valid_plugin_syntax?) ).to_html.strip
html.gsub!( %r!<span class="plugin">\{\{(.+?)\}\}</span>!m ) do
- "<%=#{CGI.unescapeHTML($1)}%>"
+ "<%=#{CGI.unescapeHTML($1)}\n%>"
end
html.gsub!( %r!<div class="plugin">\{\{(.+?)\}\}</div>!m ) do
- "<p><%=#{CGI.unescapeHTML($1)}%></p>"
+ "<p><%=#{CGI.unescapeHTML($1)}\n%></p>"
end
html.gsub!( %r!<a href="(.+?)">(.+?)</a>! ) do
k, u = $2, $1
--
[田中 哲][たなか あきら][Tanaka Akira]
|