ずんだあんです
> smbdです
> emptdiary を試用して気付いた点なのですが
> pre plugin を使用する際は行頭の空白は許されないのでしょうか?
ご指摘ありがとうございました。to_html4やto_chtmlで、行頭に空白がある場合
には、行ごとに処理をする部分が残っていたため、ヒアドキュメントのそれぞれ
の行がばらばらに処理されてしまっていたのが原因でした。
> これは既知の不具合なんでしょうか?それとも何か設定がおかしいのでしょうか?
というわけで未知の不具合でした。(僕は、しこしこ<p>〜</p>を書いてた…
<%と%>の間では文字列をぶった切らないような処理に変えてみました。
ドキュメントの更新 (最新版のダウンロード元URLを更新しました) と一緒にパ
ッチをつくりました。大きくてすみませんが、お試しください。
Index: misc/style/emptdiary/README.rd
===================================================================
RCS file: /cvsroot/tdiary/core/misc/style/emptdiary/README.rd,v
retrieving revision 1.3
diff -u -r1.3 README.rd
--- misc/style/emptdiary/README.rd 25 Feb 2003 08:56:41 -0000 1.3
+++ misc/style/emptdiary/README.rd 26 Feb 2003 10:40:55 -0000
@@ -15,10 +15,10 @@
きます。
((:emptDiaryスタイル:))の最新版は、
-((<URL:http://zunda.freeshell.org/d/tdiary/emptdiary_style.rb>))から、
+((<URL:http://zunda.freeshell.org/d/misc/style/emptdiary/emptdiary_style.rb>))から、
このファイルの最新版は、
-((<URL:http://zunda.freeshell.org/d/tdiary/emptdiary_style.rd.ja>))から
-入手できるでしょう。
+((<URL:http://zunda.freeshell.org/d/misc/style/emptdiary/README.rd>))か
+ら、 入手できるでしょう。
また、pre.rbの最新版は、
((<URL:http://zunda.freeshell.org/d/plugin/pre.rb>))から入手できるはずで
Index: misc/style/emptdiary/README.rd.en
===================================================================
RCS file: /cvsroot/tdiary/core/misc/style/emptdiary/README.rd.en,v
retrieving revision 1.3
diff -u -r1.3 README.rd.en
--- misc/style/emptdiary/README.rd.en 25 Feb 2003 08:56:43 -0000 1.3
+++ misc/style/emptdiary/README.rd.en 26 Feb 2003 10:40:55 -0000
@@ -14,10 +14,11 @@
empty lines in the arguments of plug-ins. Thus, using e.g. pre.rb
plugin, you can show your program list without modifying your it.
+
The latest version of this style can be downloaded from
-((<URL:http://zunda.freeshell.org/d/tdiary/emptdiary_style.rb>)), and
-the latest version of this document can be downloaded from
-((<URL:http://zunda.freeshell.org/d/tdiary/emptdiary_style.rd.en>)).
+((<URL:http://zunda.freeshell.org/d/misc/style/emptdiary/emptdiary_style.rb>)),
+and the latest version of this document can be downloaded from
+((<URL:http://zunda.freeshell.org/d/misc/style/emptdiary/README.rd.en>)).
== Usage
If you want to use this style
Index: misc/style/emptdiary/emptdiary_style.rb
===================================================================
RCS file: /cvsroot/tdiary/core/misc/style/emptdiary/emptdiary_style.rb,v
retrieving revision 1.1
diff -u -r1.1 emptdiary_style.rb
--- misc/style/emptdiary/emptdiary_style.rb 18 Feb 2003 01:38:04 -0000 1.1
+++ misc/style/emptdiary/emptdiary_style.rb 26 Feb 2003 10:40:55 -0000
@@ -6,20 +6,24 @@
arguments to have empty lines. In short, this style preserves empty
lines between <% and %> when splltting the input into sections.
-The latest version of this file shall be downloaded from
-((<URL:http://zunda.freeshell.org/d/tdiary/emptdiary_style.rb>)).
+The latest version of this file can be downloaded from
+((<URL:http://zunda.freeshell.org/d/misc/style/emptdiary/emptdiary_style.rb>)).
== Usage
if you want to use this style, add the following line into tdiary.conf:
@style = 'emptdiary'
-Please see emptdiary_style.rd.ja or emptdiary_style.rd.en for further
-explanation.
+Please see README.rd or README.rd.en for further explanation.
== Acknowledgements
This style is realized using TdiarySection and TdiaryDiary as
super-classes. I thank the authors of tdiary_style.rb for providing such
flexible classes.
+EmptdiaryDiary::to_html4 and EmptdiaryDiary::to_chtml are copied from
+tdiary_style.rb and slightly edited as follows:
+* split_unless_plugin() is inserted before each collect()
+* Regexp is chanegd from ^ to \A
+
== Copyright
Copyright 2003 zunda <zunda at freeshell.org>
@@ -30,20 +34,73 @@
=begin ChangeLog
* Mon Feb 17, 2003 zunda <zunda at freeshell.org>
- copied from zunda_style.rb, with which I used for preliminary tests.
+* Wed Feb 26, 2003 zunda <zunda at freeshell.org>
+- TDiary::Emptdiary::String class to handle strings better
+ (Thanks to Mitsuru Shimamura <mitsuru at diana.dti.ne.jp> for the
+ error report)
=end
require 'tdiary/tdiary_style'
+=begin
+== Classes and methods defined in this style
+Please note that not all are documented.
+=end
+
module TDiary
+=begin
+=== TDiary::Emptdiary::EmptdiaryString < String
+Extended String class not to divide things between <% and %>.
+
+--- TDiary::Emptdiary::EmptdiaryString.split_unless_plugin ( delimiter = "\n\n" )
+ Returns an array of EmptdiaryString splitted at ((|delimiter|))
+ which is outside of <% and %> pairs. Specify ((|delimiter|)) as a
+ String showing a fragment of Regexp. This will be combined in a
+ Regexp like: /(#{delimiter)|<%|%>)/.
+=end
+ class Emptdiary
+ class EmptdiaryString < String
+ def split_unless_plugin( delimiter = "\n\n+" )
+ result = Array.new
+ fragment = ''
+ nest = 0
+ remain = self.gsub(/.*?(#{delimiter}|<%|%>)/m) do
+ fragment += $&
+ case $1
+ when '<%'
+ nest += 1
+ when '%>'
+ nest -= 1
+ else
+ if nest == 0 then
+ fragment.sub!( /#{delimiter}\z/, '' )
+ result << Emptdiary::EmptdiaryString.new( fragment ) unless fragment.empty?
+ fragment = ''
+ end
+ end
+ ''
+ end
+ fragment += remain
+ fragment.sub!( /#{delimiter}\z/, '' )
+ result << Emptdiary::EmptdiaryString.new( fragment ) unless fragment.empty?
+ result
+ end
+ end
+ end
+
+=begin
+=== TDiary::EmptdiartySection < TdiarySection
+Almost the same as TdiarySection but usess split_unless_plugin instead
+of split. initialize method is overrideen.
+=end
class EmptdiarySection < TdiarySection
def initialize( fragment, author = nil )
@author = author
- lines = fragment.split( /\n/, 2 )
- # we only have to divide the text into title and body
+ lines = fragment.split_unless_plugin( "\n+" )
if lines.size > 1 then
- if /^<</ =~ lines[0]
- @subtitle = lines.shift.chomp.sub( /^</, '' )
- elsif /^[ <]/e !~ lines[0]
+ if /\A<</ =~ lines[0]
+ @subtitle = lines.shift.chomp.sub( /\A</, '' )
+ elsif /\A[ <]/e !~ lines[0]
@subtitle = lines.shift.chomp
end
end
@@ -53,42 +110,83 @@
end
end
+=begin
+=== TDiary::EmptdiaryDiary < TdiaryDiary
+Almost the same as TdiarySection but usess split_unless_plugin instead
+of split. append method is overriden and makes EmptdiarySection with
+body being an EmptdiaryString. Also, to_html4 and to_chtml methods are
+overridden to split_unless_plugin before collect'ing the body of the
+sections.
+=end
class EmptdiaryDiary < TdiaryDiary
def style
'emptdiary'
end
def append( body, author = nil )
- # first make an array of sections
- sections = Array.new
- fragment = ''
- nest = 0
- remain = (body.gsub("\r", '')+"\n\n").gsub(/.*?(\n\n+|<%|%>)/m) do
- fragment += $&
- case $1
- when '<%'
- nest += 1
- when '%>'
- nest -= 1
- else
- if nest == 0 then
- fragment.sub! (/\n+\z/, '')
- sections << fragment unless fragment.empty?
- fragment = ''
- end
- end
- ''
- end
- fragment += remain
- fragment.sub! (/\n+\z/, '')
- sections << fragment unless fragment.empty?
- # add the sections to the diary
- sections.each do |fragment|
+ Emptdiary::EmptdiaryString.new(body.sub( "\r", '' )).split_unless_plugin( "\n\n+" ).each do |fragment|
section = EmptdiarySection::new( fragment, author )
@sections << section if section
end
@last_modified = Time::now
self
end
+
+ def to_html4( opt )
+ idx = 1
+ r = ''
+ each_section do |section|
+ r << %Q[<div class="section">\n]
+ if section.subtitle then
+ r << %Q[<h3><a ]
+ if opt['anchor'] then
+ r << %Q[name="p#{'%02d' % idx}" ]
+ end
+ r << %Q[href="#{opt['index']}<%=anchor "#{date.strftime( '%Y%m%d' )}#p#{'%02d' % idx}" %>">#{opt['section_anchor']}</a> ]
+ if opt['multi_user'] and section.author then
+ r << %Q|[#{section.author}]|
+ end
+ r << %Q[#{section.categorized_subtitle}</h3>]
+ end
+ if /\A</ =~ section.body then
+ r << %Q[#{section.body}]
+ elsif section.subtitle
+ r << %Q[<p>#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[ ]/e, '')}.join( "</p>\n<p>" )}</p>]
+ else
+ r << %Q[<p><a ]
+ if opt['anchor'] then
+ r << %Q[name="p#{'%02d' % idx}" ]
+ end
+ r << %Q[href="#{opt['index']}<%=anchor "#{date.strftime( '%Y%m%d' )}#p#{'%02d' % idx}" %>">#{opt['section_anchor']}</a> #{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[ ]/e, '' )}.join( "</p>\n<p>" )}</p>]
+ end
+ r << %Q[</div>]
+ idx += 1
+ end
+ r
+ end
+
+ def to_chtml( opt )
+ idx = 0
+ r = ''
+ each_section do |section|
+ if section.subtitle then
+ r << %Q[<P><A NAME="p#{'%02d' % idx += 1}">*</A> #{section.subtitle}</P>]
+ end
+ if /\A</ =~ section.body then
+ idx += 1
+ r << section.body
+ elsif section.subtitle
+ r << %Q[<P>#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[ ]/e, '' )}.join( "</P>\n<P>" )}</P>]
+ else
+ r << %Q[<P><A NAME="p#{'%02d' % idx += 1}">*</A> ]
+ if opt['multi_user'] and section.author then
+ r << %Q|[#{section.author}]|
+ end
+ r << %Q[#{section.body.split_unless_plugin( "\n+" ).collect{|l|l.chomp.sub( /\A[ ]/e, '' )}.join( "</P>\n<P>" )}</P>]
+ end
+ end
+ r
+ end
+
end
end
|