Module manubot.cite
View Source
__all__ = [
"citekey_to_csl_item",
]
from manubot.cite.citekey import citekey_to_csl_item
Sub-modules
- manubot.cite.arxiv
- manubot.cite.citations
- manubot.cite.cite_command
- manubot.cite.citekey
- manubot.cite.citeproc
- manubot.cite.csl_item
- manubot.cite.curie
- manubot.cite.doi
- manubot.cite.handlers
- manubot.cite.isbn
- manubot.cite.pubmed
- manubot.cite.tests
- manubot.cite.unpaywall
- manubot.cite.url
- manubot.cite.wikidata
- manubot.cite.zotero
Functions
citekey_to_csl_item
def citekey_to_csl_item(
citekey,
prune=True,
manual_refs=None,
log_level: Union[str, int] = 'WARNING'
)
Generate a CSL_Item for the input citekey.
View Source
def citekey_to_csl_item(
citekey, prune=True, manual_refs=None, log_level: tp.Union[str, int] = "WARNING"
):
"""
Generate a CSL_Item for the input citekey.
"""
from manubot import __version__ as manubot_version
if manual_refs is None:
manual_refs = {}
# https://stackoverflow.com/a/35704430/4651668
log_level = logging._checkLevel(log_level)
if not isinstance(citekey, CiteKey):
citekey = CiteKey(citekey)
if citekey.standard_id in manual_refs:
return manual_refs[citekey.standard_id]
try:
csl_item = citekey.csl_item
except Exception as error:
logging.log(
log_level,
f"Generating csl_item for {citekey.standard_id!r} failed "
f"due to a {error.__class__.__name__}:\n{error}",
)
logging.info(error, exc_info=True)
return None
# update csl_item with manubot generated metadata
note_text = f"This CSL Item was generated by Manubot v{manubot_version} from its persistent identifier (standard_id)."
note_dict = {"standard_id": citekey.standard_id}
csl_item.note_append_text(note_text)
csl_item.note_append_dict(note_dict)
csl_item.set_id(citekey.short_id)
csl_item.clean(prune=prune)
return csl_item