Merge pull request 'dev0.21' (#2) from dev0.21 into master
Reviewed-on: #2
This commit is contained in:
commit
a2c8e24ffe
12
README.md
12
README.md
|
@ -15,6 +15,10 @@ Create an _citation.ini_ in its _configs_-folder:
|
|||
```
|
||||
[Bibtex]
|
||||
file = Literature.bib
|
||||
|
||||
[default]
|
||||
priority = url
|
||||
link = /for-example/link-to-your/biblioprahy
|
||||
```
|
||||
|
||||
And put a _Literature.bib_ BibTex-file into the project's _assets_-folder respectively.
|
||||
|
@ -94,5 +98,11 @@ Both methods create a complete hyperlink inside your text for the entry with _id
|
|||
or
|
||||
|
||||
(AuthorI & AuthorII, 2019)
|
||||
|
||||
|
||||
#### link parameter
|
||||
Which url is used for your citation's link depends on what you set in the _citation.ini_ file.
|
||||
* If you set _priority_ in the _default_ section to __url__ the link is set to the value of the _url_ field of the entry.
|
||||
* If there's no value in it the default-link you may set with _link_ in the same section is used.
|
||||
* If you set the _link_ parameter of the function it overwrites the former options.
|
||||
|
||||
Thanks to the **lektor-jinja-content** plugin which is a dependency of this plugin you might also use the globals inside your markdown or html contents, too.
|
||||
|
|
|
@ -15,6 +15,8 @@ class CitationPlugin(Plugin):
|
|||
|
||||
config = self.get_config()
|
||||
self.bibfile = config.get('Bibtex.file', []).strip()
|
||||
self.default_prio = config.get('default.priority', []).strip()
|
||||
self.default_link = config.get('default.link', []).strip()
|
||||
|
||||
self.bib_data = parse_file(os.path.join(env.root_path, 'assets', self.bibfile))
|
||||
|
||||
|
@ -46,7 +48,7 @@ class CitationPlugin(Plugin):
|
|||
if len(lAuthor) > 1:
|
||||
|
||||
if n == (len(lAuthor) - 1):
|
||||
authors += " \& "
|
||||
authors += " & "
|
||||
elif n < (len(lAuthor) -1):
|
||||
authors += ", "
|
||||
|
||||
|
@ -77,7 +79,7 @@ class CitationPlugin(Plugin):
|
|||
if len(lAuthor) > 1:
|
||||
|
||||
if n == (len(lAuthor) - 1):
|
||||
authors += " \& "
|
||||
authors += " & "
|
||||
elif n < (len(lAuthor) -1):
|
||||
authors += ", "
|
||||
|
||||
|
@ -223,24 +225,35 @@ class CitationPlugin(Plugin):
|
|||
""".format(eid = id, link = link, authors = authors, pubYear = year, title = title, edition = edition, publisher = publisher, editors = editors, pages = pages, issbn = issbn, note = note)
|
||||
return output
|
||||
|
||||
def citation_full_cite(self,id,link=""):
|
||||
def citation_base_cite(self,id,link="",output=""):
|
||||
e = self.citation_entry(id)
|
||||
|
||||
if len(link) > 1:
|
||||
link = link
|
||||
elif self.default_prio == "url":
|
||||
link = self.get_url(e)
|
||||
if len(link) < 2:
|
||||
link = self.default_link
|
||||
else:
|
||||
link = self.default_link
|
||||
|
||||
authors = self.get_authors_short(e)
|
||||
year = self.get_pubYear(e)
|
||||
output = """<a href=\"{link}#{id}\" class=\"litref\">({authors}, {pubYear})</a>""".format(link = link, id = id, authors = authors, pubYear = year)
|
||||
output = output.format(link = link, id = id, authors = authors, pubYear = year)
|
||||
return output
|
||||
|
||||
def citation_full_cite(self,id,link=""):
|
||||
output = self.citation_base_cite(id,link="",output="""<a href=\"{link}#{id}\" class=\"litref\">({authors}, {pubYear})</a>""")
|
||||
return output
|
||||
|
||||
def citation_full_citeNP(self,id,link=""):
|
||||
e = self.citation_entry(id)
|
||||
authors = self.get_authors_short(e)
|
||||
year = self.get_pubYear(e)
|
||||
output = """<a href=\"{link}#{id}\" class=\"litref\">{authors} ({pubYear})</a>""".format(link = link, id = id, authors = authors, pubYear = year)
|
||||
output = self.citation_base_cite(id,link="",output="""<a href=\"{link}#{id}\" class=\"litref\">{authors} ({pubYear})</a>""")
|
||||
return output
|
||||
|
||||
def on_setup_env(self, **extra):
|
||||
def decode_filter(value):
|
||||
""" Make sure that special chars like german umlaute or accents are displayed in unicode """
|
||||
return LatexNodes2Text().latex_to_text(value)
|
||||
return LatexNodes2Text().latex_to_text(value.replace(" & ", " \& "))
|
||||
|
||||
self.env.jinja_env.globals['citation_entries'] = self.citation_entries
|
||||
self.env.jinja_env.globals['citation_entry'] = self.citation_entry
|
||||
|
|
Loading…
Reference in New Issue