Sha256: d3325e16a81db5dcabf426ed6aafb254724c7be7db87d407f45152432825e4bb

Contents?: true

Size: 1.79 KB

Versions: 22

Compression:

Stored size: 1.79 KB

Contents

# -*- coding: utf-8 -*-
# footnote.rb
#
# fn: 脚注plugin
#   パラメタ:
#     text: 脚注本文
#     mark: 脚注マーク('*')
#
# Copyright (C) 2007 TADA Tadashi <sho@spc.gr.jp>
# Distributed under the GPL.

# initialize variables
@fn_fragment_fm = ''
@fn_fragment_f = ''
@fn_notes = []
@fn_marks = []

add_body_enter_proc do |date|
	fn_initialize( date )
	''
end

add_section_enter_proc do |date, index|
	fn_initialize( date, index ) unless @conf.style =~ /blog/i
	''
end

def fn_initialize( date, section = 1 )
	@fn_fragment_fm = sprintf( 'fm%s-%02d-%%02d', date.strftime( '%Y%m%d' ), section )
	@fn_fragment_f = @fn_fragment_fm.sub( /^fm/, 'f' )
	@fn_notes = []
	@fn_marks = []
end

def fn( text, mark = '*' )
	@fn_notes += [text]
	@fn_marks += [mark]
	idx = @fn_notes.size

	r = %Q|<span class="footnote">|
	if feed? then
		r << %Q|#{mark}#{idx}|
	else
		r << %Q|<a |
		r << %Q|name="#{@fn_fragment_fm % idx}" |
		r << %Q|href="##{@fn_fragment_f % idx}" |
		r << %Q|title="#{h text}">|
		r << %Q|#{h mark}#{idx}|
		r << %Q|</a>|
	end
	r << %Q|</span>|
end

# print footnotes
add_section_leave_proc do |date, index|
	@conf.style =~ /blog/i ? '' : fn_put
end

add_body_leave_proc do |date|
	fn_put
end

def fn_put
	if @fn_notes.size > 0 then
		r = %Q|<div class="footnote">\n|
		@fn_notes.each_with_index do |fn, idx|
			r << %Q|\t<p class="footnote">|
			if feed? then
				r << %Q|#{h @fn_marks[idx]}#{idx+1}|
			else
				r << %Q|<a |
				r << %Q|name="#{@fn_fragment_f % (idx+1)}" |
				r << %Q|href="##{@fn_fragment_fm % (idx+1)}">|
				r << %Q|#{h @fn_marks[idx]}#{idx+1}|
				r << %Q|</a>|
			end
			r << %Q|&nbsp;#{@fn_notes[idx]}</p>\n|
		end
		@fn_notes.clear
		r << %Q|</div>\n|
	else
		''
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:
# vim: ts=3

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
tdiary-4.0.5.1 misc/plugin/footnote.rb
tdiary-4.0.5 misc/plugin/footnote.rb
tdiary-4.0.4 misc/plugin/footnote.rb
tdiary-4.0.3 misc/plugin/footnote.rb
tdiary-4.0.2.20140201 misc/plugin/footnote.rb
tdiary-4.0.2 misc/plugin/footnote.rb
tdiary-4.0.1.20131102 misc/plugin/footnote.rb
tdiary-4.0.1.20130929 misc/plugin/footnote.rb
tdiary-4.0.1.20130903 misc/plugin/footnote.rb
tdiary-4.0.1 misc/plugin/footnote.rb
tdiary-4.0.0.20130826 misc/plugin/footnote.rb
tdiary-4.0.0 misc/plugin/footnote.rb
tdiary-3.2.2.20130727 misc/plugin/footnote.rb
tdiary-3.2.2.20130722 misc/plugin/footnote.rb
tdiary-3.2.2.20130720 misc/plugin/footnote.rb
tdiary-3.2.2.20130617 misc/plugin/footnote.rb
tdiary-3.2.2.20130614 misc/plugin/footnote.rb
tdiary-3.2.2.20130604 misc/plugin/footnote.rb
tdiary-3.2.2.20130527 misc/plugin/footnote.rb
tdiary-3.2.2.20130518 misc/plugin/footnote.rb