# -*- coding: utf-8 -*- import os from pylatexenc.latex2text import LatexNodes2Text from pybtex.database import parse_file from lektor.pluginsystem import Plugin class CitationPlugin(Plugin): name = 'lektor-citation' description = u'This Plugin should extend lektor with APA-style citations using bibtex files. It is based on the known lektor-bibtex-support plugin by arunpersaud.' def __init__(self, env, id): super().__init__(env, id) config = self.get_config() self.bibfile = config.get('Bibtex.file', []).strip() self.bib_data = parse_file(os.path.join(env.root_path, 'assets', self.bibfile)) def citation_entries(self): return self.bib_data.entries def citation_entry(self, id): return self.bib_data.entries[id] def on_setup_env(self, **extra): self.env.jinja_env.globals['citation_entries'] = self.citation_entries self.env.jinja_env.globals['citation_entry'] = self.citation_entry