diff --git a/features/details.feature b/features/details.feature index c0741e042e7b08fdb73e0e497d8fa03948997bca..14e6feab4c8ba1f18108dde730fd1489fd43efd8 100644 --- a/features/details.feature +++ b/features/details.feature @@ -36,6 +36,71 @@ Feature: BibTeX And the "_site/bibliography/ruby.html" file should exist And I should see "The Ruby Programming Language" in "_site/bibliography/ruby.html" + @generators + Scenario: LaTeX conversion is applied to everything except the bibtex field + Given I have a scholar configuration with: + | key | value | + | source | ./_bibliography | + | details_layout | details.html | + And I have a "_bibliography" directory + And I have a file "_bibliography/references.bib": + """ + @book{ruby, + title = {An Umlaut \"a!}, + } + """ + And I have a "_layouts" directory + And I have a file "_layouts/details.html": + """ + --- + --- + + + + Title: {{ page.entry.title }} + {{ page.entry.bibtex }} + + + """ + When I run jekyll + Then the _site directory should exist + And the "_site/bibliography/ruby.html" file should exist + And I should see "Title: An Umlaut รค!" in "_site/bibliography/ruby.html" + And I should see "title = {An Umlaut \\\"a!}" in "_site/bibliography/ruby.html" + + @generators + Scenario: LaTeX conversion can be turned off + Given I have a scholar configuration with: + | key | value | + | source | ./_bibliography | + | details_layout | details.html | + | bibtex_filters | | + And I have a "_bibliography" directory + And I have a file "_bibliography/references.bib": + """ + @book{ruby, + title = {An Umlaut \"a!}, + } + """ + And I have a "_layouts" directory + And I have a file "_layouts/details.html": + """ + --- + --- + + + + Title: {{ page.entry.title }} + {{ page.entry.bibtex }} + + + """ + When I run jekyll + Then the _site directory should exist + And the "_site/bibliography/ruby.html" file should exist + And I should see "Title: An Umlaut \\\"a!" in "_site/bibliography/ruby.html" + And I should see "title = {An Umlaut \\\"a!}" in "_site/bibliography/ruby.html" + @tags @details Scenario: Links to Detail Pages are Generated Automatically Given I have a scholar configuration with: diff --git a/lib/jekyll/scholar/defaults.rb b/lib/jekyll/scholar/defaults.rb index 81551cc392a6db344126f8a9ea425546571c7a4b..494440ad423a9e27ad4747eaaa7c0759db511662 100644 --- a/lib/jekyll/scholar/defaults.rb +++ b/lib/jekyll/scholar/defaults.rb @@ -10,6 +10,9 @@ module Jekyll 'source' => './_bibliography', 'bibliography' => 'references.bib', + 'bibtex_options' => { :strip => false }, + 'bibtex_filters' => [ :latex ], + 'details_dir' => 'bibliography', 'details_layout' => 'bibtex.html', 'details_link' => 'Details', diff --git a/lib/jekyll/scholar/generators/details.rb b/lib/jekyll/scholar/generators/details.rb index 61d81576a33286447c25e98dccd96463f50c8fb5..8fbc5c3ab8be482f7c1d3cd6d9b24dd5a59037b0 100644 --- a/lib/jekyll/scholar/generators/details.rb +++ b/lib/jekyll/scholar/generators/details.rb @@ -26,9 +26,10 @@ module Jekyll data['entry']['type'] = entry.type data['entry']['bibtex'] = entry.to_s - + entry.fields.each do |key, value| - data['entry'][key.to_s] = value.convert(:latex).to_s + value = value.convert(*bibtex_filters) unless bibtex_filters.empty? + data['entry'][key.to_s] = value.to_s end end diff --git a/lib/jekyll/scholar/utilities.rb b/lib/jekyll/scholar/utilities.rb index b70c61d3198271d9139f77c4e39729a65e65ac80..855170caf53e7be7a6c424b0581e31c164079f4a 100644 --- a/lib/jekyll/scholar/utilities.rb +++ b/lib/jekyll/scholar/utilities.rb @@ -40,7 +40,11 @@ module Jekyll end def bibtex_options - @bibtex_options ||= { :strip => false } + config['bibtex_options'] ||= {} + end + + def bibtex_filters + config['bibtex_filters'] ||= [] end def bibtex_path @@ -82,7 +86,7 @@ module Jekyll def reference_tag(entry) return missing_reference unless entry - entry = entry.convert(:latex) + entry = entry.convert(*bibtex_filters) unless bibtex_filters.empty? reference = CiteProc.process entry.to_citeproc, :style => config['style'], :locale => config['locale'], :format => 'html' @@ -142,13 +146,15 @@ module Jekyll context['cited'] << key if bibliography.key?(key) - entry = bibliography[key].convert(:latex) + entry = bibliography[key] + entry = entry.convert(*bibtex_filters) unless bibtex_filters.empty? + citation = CiteProc.process entry.to_citeproc, :style => config['style'], :locale => config['locale'], :format => 'html', :mode => :citation link_to "##{[prefix, entry.key].compact.join('-')}", citation.join else - '(missing reference)' + missing_reference end rescue "(#{key})" @@ -158,7 +164,7 @@ module Jekyll if bibliography.key?(key) link_to details_link_for(bibliography[key]), text || config['details_link'] else - '(missing reference)' + missing_reference end end