lib/jekyll/zettel/citedown.rb in jekyll-zettel-0.7.1 vs lib/jekyll/zettel/citedown.rb in jekyll-zettel-0.7.2

- old
+ new

@@ -3,14 +3,21 @@ # Kramdown Parser mit inline Zitationen class Citedown < Kramdown def initialize(source, options) super - @citeproc = Jekyll.sites[0].config['citeproc'] - @references = Jekyll.sites[0].data['references'] - @zettel = Jekyll.sites[0].data['zettelkasten'] - @span_parsers.unshift(:citation) + 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 CITATION = /\[@([\w,:]+)(;\s*(.*))?\]/.freeze def parse_citation @@ -21,32 +28,60 @@ note = @src[3] if @references.key?(cite_key) add_citation(cite_key, note, start_line_number) else - add_error(cite_key) + log_warning('cite-key', cite_key) end end 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']]['description'], - 'style' => 'box-shadow: initial; border: none;' + '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 - def add_error(cite_key) - Jekyll.logger.warn 'Zettel:', "Missing entry for cite-key @#{cite_key}" - @tree.children << Element.new(:raw, "<span class=\"error\">Missing entry for cite-key @#{cite_key}</span>") + define_parser(:citation, CITATION, '\[@') + + KEYWORD = /\[#([\w]+)\]/.freeze + + 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 - define_parser(:citation, CITATION, '\[@') + 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 + + define_parser(:keyword, KEYWORD, '\[#') + + 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 end end end # options => {