Class: Gollum::Filter::BibTeX

Inherits:
Gollum::Filter show all
Defined in:
lib/gollum-lib/filter/bibtex.rb

Overview

Render BibTeX files.

Constant Summary

Constants inherited from Gollum::Filter

PLACEHOLDER_PATTERN

Instance Attribute Summary

Attributes inherited from Gollum::Filter

#close_pattern, #open_pattern

Instance Method Summary collapse

Methods inherited from Gollum::Filter

#initialize

Methods included from Helpers

#path_to_link_text, #trim_leading_slashes

Constructor Details

This class inherits a constructor from Gollum::Filter

Instance Method Details

#extract(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gollum-lib/filter/bibtex.rb', line 12

def extract(data)
  return data unless supported_format? && gems_available? && bib = ::BibTeX.parse(data).convert(:latex)
  style = find_csl_data('csl') || ::CSL::Style.default
  locale = find_csl_data('locale') || ::CSL::Locale.default

  begin
    style = ::CSL::Style.load(style)
    ::CSL::Locale.load(locale)
  rescue ::CSL::ParseError => error
    log_failure(error.to_s)
    return CGI.escapeHTML(data)
  end

  citeproc = ::CiteProc::Processor.new(style: style, locale: locale, format: 'html')
  citeproc.import(bib.to_citeproc)
  citeproc.bibliography.references.join('<br/>')
end

#process(data) ⇒ Object



30
31
32
# File 'lib/gollum-lib/filter/bibtex.rb', line 30

def process(data)
  data
end