lib/jekyll/zettel/citedown.rb in jekyll-zettel-0.7.0 vs lib/jekyll/zettel/citedown.rb in jekyll-zettel-0.7.1
- old
+ new
@@ -9,18 +9,27 @@
@references = Jekyll.sites[0].data['references']
@zettel = Jekyll.sites[0].data['zettelkasten']
@span_parsers.unshift(:citation)
end
- CITATION = /\(@([\w,:]+)(;\s*(.*))?\)/.freeze
+ CITATION = /\[@([\w,:]+)(;\s*(.*))?\]/.freeze
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
+ add_error(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;'
@@ -29,10 +38,15 @@
link.children << Element.new(:raw, "<sup>#{citation}</sup>")
@tree.children << link
end
- define_parser(:citation, CITATION, '\(@')
+ 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>")
+ end
+
+ define_parser(:citation, CITATION, '\[@')
end
end
end
# options => {