Class: Kramdown::Parser::Citedown
- Defined in:
- lib/jekyll/zettel/citedown.rb
Overview
Kramdown Parser mit inline Zitationen
Constant Summary collapse
- CITATION =
/\[@([\w,:]+)(;\s*(.*))?\]/.freeze
- KEYWORD =
/\[#([\w]+)\]/.freeze
Instance Method Summary collapse
- #add_citation(cite_key, note, start_line_number) ⇒ Object
- #add_keyword(keyword, start_line_number) ⇒ Object
-
#initialize(source, options) ⇒ Citedown
constructor
A new instance of Citedown.
- #log_warning(catalog, entry) ⇒ Object
- #parse_citation ⇒ Object
- #parse_keyword ⇒ Object
Constructor Details
#initialize(source, options) ⇒ Citedown
Returns a new instance of Citedown.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jekyll/zettel/citedown.rb', line 6 def initialize(source, ) super site = Jekyll.sites[0] @citeproc = site.config['citeproc'] @references = site.data['references'] @keywords = site.data['aliases'] @zettel = site.data['zettelkasten'] @span_parsers.unshift(:citation, :keyword) # So geht’s mit <i>, <b>, <em> und <strong> weiter # @span_parsers.delete(:emphasis) end |
Instance Method Details
#add_citation(cite_key, note, start_line_number) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jekyll/zettel/citedown.rb', line 37 def add_citation(cite_key, note, start_line_number) citation = @citeproc.render :citation, id: cite_key, locator: note, label: :note attributes = { 'href' => "/zettel/#{@references[cite_key]['id']}/", 'title' => @zettel[@references[cite_key]['id']]['title'], 'class' => 'citation' } link = Element.new(:a, nil, attributes, location: start_line_number) link.children << Element.new(:raw, "<sup>#{citation}</sup>") @tree.children << link end |
#add_keyword(keyword, start_line_number) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/jekyll/zettel/citedown.rb', line 66 def add_keyword(keyword, start_line_number) attributes = { 'href' => "/glosse/#{@keywords[keyword]['slug']}/", 'title' => @keywords[keyword]['tag'], 'class' => 'keyword' } link = Element.new(:a, nil, attributes, location: start_line_number) link.children << Element.new(:raw, keyword) @tree.children << link end |
#log_warning(catalog, entry) ⇒ Object
80 81 82 83 |
# File 'lib/jekyll/zettel/citedown.rb', line 80 def log_warning(catalog, entry) Jekyll.logger.warn 'Zettel:', "Missing entry for #{catalog} `#{entry}`" @tree.children << Element.new(:raw, "<span class=\"error\">Missing entry for #{catalog} `#{entry}`</span>") end |
#parse_citation ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jekyll/zettel/citedown.rb', line 23 def parse_citation start_line_number = @src.current_line_number @src.pos += @src.matched_size cite_key = @src[1] note = @src[3] if @references.key?(cite_key) add_citation(cite_key, note, start_line_number) else log_warning('cite-key', cite_key) end end |
#parse_keyword ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jekyll/zettel/citedown.rb', line 54 def parse_keyword start_line_number = @src.current_line_number @src.pos += @src.matched_size keyword = @src[1] if @keywords.key?(keyword) add_keyword(keyword, start_line_number) else log_warning('keyword', keyword) end end |