def citekey_to_csl_item(citekey, prune=True): """ Generate a CSL Item (Python dictionary) for the input citekey. """ from manubot.cite.csl_item import CSL_Item from manubot import __version__ as manubot_version citekey == standardize_citekey(citekey, warn_if_changed=True) source, identifier = citekey.split(':', 1) if source not in citeproc_retrievers: msg = f'Unsupported citation source {source!r} in {citekey!r}' raise ValueError(msg) citeproc_retriever = import_function(citeproc_retrievers[source]) csl_item = citeproc_retriever(identifier) csl_item = CSL_Item(csl_item) note_text = f'This CSL JSON Item was automatically generated by Manubot v{manubot_version} using citation-by-identifier.' note_dict = { 'standard_id': citekey, } csl_item.note_append_text(note_text) csl_item.note_append_dict(note_dict) short_citekey = shorten_citekey(citekey) csl_item.set_id(short_citekey) csl_item.clean(prune=prune) return csl_item
def test_clean_set_id(self): csl_item = CSL_Item(type="chapter") csl_item.set_id("abc") csl_item.clean(prune=True) assert csl_item == {"type": "chapter", "id": "abc"}
def test_clean_set_id(self): csl_item = CSL_Item(type='chapter') csl_item.set_id('abc') csl_item.clean(prune=True) assert csl_item == {'type': 'chapter', 'id': 'abc'}