module WikiCloth class ReferencesExtension < Extension # reference content # reference content # # reference content # element 'ref' do |buffer| # find our named reference reference if it exists named_ref = buffer.get_attribute_by_name("name") ref = @options[:link_handler].find_reference_by_name(named_ref) unless named_ref.nil? # reference either not "named" or first time in document if ref.nil? @options[:link_handler].references << { :name => named_ref, :value => buffer.element_content, :count => 0, :group => buffer.get_attribute_by_name("group") } ref = @options[:link_handler].references.last end ref_id = (named_ref.nil? ? "" : "#{named_ref}_") + "#{@options[:link_handler].reference_index(ref)}-#{ref[:count]}" cite_anchor = "#cite_note-" + (named_ref.nil? ? "" : "#{named_ref}_") + @options[:link_handler].reference_index(ref).to_s group_label = buffer.get_attribute_by_name("group") ? "#{buffer.get_attribute_by_name("group")} " : "" ref_link = "#{@options[:link_handler].reference_index(ref)}" ref[:count] += 1 "[#{group_label}#{ref_link}]" end # # # element 'references' do |buffer| ref_count = 0 group_match = buffer.get_attribute_by_name("group") refs = @options[:link_handler].references.collect { |r| next if r[:group] != group_match ref_count += 1 ref_name = (r[:name].nil? ? "" : r[:name].to_slug + "_") ret = "
  • " 1.upto(r[:count]) { |x| ret += "" + (r[:count] == 1 ? "^" : (x-1).to_s(26).tr('0-9a-p', 'a-z')) + " " } ret += " #{r[:value]}
  • " }.join("\n") "
      #{refs}
    " end end end