示例#1
0
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
示例#2
0
def test_csl_item_note_append(input_note, text, dictionary, expected_note):
    csl_item = CSL_Item({
        "id": "test_csl_item",
        "type": "entry",
        "note": input_note
    })
    csl_item.note_append_text(text)
    csl_item.note_append_dict(dictionary)
    assert csl_item.note == expected_note
示例#3
0
def test_csl_item_note_append(input_note, text, dictionary, expected_note):
    csl_item = CSL_Item({
        'id': 'test_csl_item',
        'type': 'entry',
        'note': input_note,
    })
    csl_item.note_append_text(text)
    csl_item.note_append_dict(dictionary)
    assert csl_item.note == expected_note