Custom CSL Style with URI

I want to be able to quickly copy information about an item in Zotero TOGETHER with its URI, e.g.
> [(Newton, 1730)](zotero://select/library/items/AU34DFCZ)

I know that BBT and Zutilo let you grab the URI, but I'm wanting to add more to the quick copy (in this example, I want to be able to place a link and have readable Author/date info, all in one step, to place in a markdown file).

How can I reference the URI in a custom citation style? Or does anyone have another suggestion?
  • The URI is not available to citation styles, so you can't do this. If you know basic javascript, you can customize the Scannable Cite translator code that comes with the ODF scan add-on, which does something similar:
    https://github.com/Juris-M/zotero-odf-scan-plugin/blob/master/resource/translators/Scannable Cite.js

    Change the ID & name, put in the Zotero translator folder (in side the Zotero data directory) and restart Zotero for it to show up.
  • Great, thank you!
    Anyone who wants to try their own variation of this, I only needed to change the lines with:

    1. "translatorID" (apply a new GUID)
    2. "label"
    3. Zotero.write() ---multiple lines
  • antdmcd, could you post your version of this somewhere? I am not that well versed in programing and I essentially want to do the same thing.

    Thanks
  • Sure, (just a note here that the three steps above are straightforward even though I am not well versed in programming, I simply modified the Scannable Cite thanks to the previous creators)
    this works for me when I save the following as MyMarkdownLink.js in my Zotero translator folder inside the Zotero data directory ( https://www.zotero.org/support/zotero_data ) :

    {
    "translatorID": "b578986e-4ac5-4735-b938-d8f2f95b850a",
    "label": "MyMarkdownLink",
    "priorlabel": "Scannable Cite",
    "priorcreator": "Scott Campbell, Avram Lyon, Nathan Schneider, Sebastian Karcher, Frank Bennett",

    "target": "html",
    "minVersion": "3.0",
    "maxVersion": "",
    "priority": 100,
    "displayOptions": {
    "exportCharset": "UTF-8"
    },
    "inRepository": true,
    "translatorType": 2,
    "browserSupport": "",
    "lastUpdated": "2020-012-17 09:13:04"
    }

    // legal types are weird
    const LEGAL_TYPES = ["bill","case","gazette","hearing","patent","regulation","statute","treaty"];
    const Mem = function (item) {
    let lst = [];
    const isLegal = LEGAL_TYPES.includes(item.itemType);
    this.set = function (str, punc, slug) { if (!punc) {punc="";} if (str) {lst.push((str + punc));} else if (!isLegal) {lst.push(slug);}};
    this.setlaw = function (str, punc) { if (!punc) {punc="";} if (str && isLegal) {lst.push(str + punc);}};
    this.get = function () { return lst.join(" "); };
    };

    function doExport() {
    let item;
    while (item = Zotero.nextItem()) {
    let mem = new Mem(item);
    let memdate = new Mem(item);
    Zotero.write("[");
    let library_id = item.libraryID ? item.libraryID : 0;
    if (item.creators.length >0){
    mem.set(item.creators[0].lastName,",");
    if (item.creators.length > 2) mem.set("et al.", ",");
    else if (item.creators.length == 2) mem.set("& " + item.creators[1].lastName, ",");
    }
    else {
    mem.set(false, ",","anon.");
    }
    if (Zotero.getHiddenPref("ODFScan.includeTitle") || item.creators.length === 0) {
    mem.set(item.title,",","(no title)");
    }
    mem.setlaw(item.authority, ",");
    mem.setlaw(item.volume);
    mem.setlaw(item.reporter);
    mem.setlaw(item.pages);
    memdate.setlaw(item.court,",");
    let date = Zotero.Utilities.strToDate(item.date);
    let dateS = (date.year) ? date.year : item.date;
    memdate.set(dateS,"","no date");
    Zotero.write(mem.get() + " " + memdate.get() + "](");
    //if (Zotero.getHiddenPref("ODFScan.useZoteroSelect")) {
    if (1) {
    Zotero.write("zotero://select/items/" + library_id + "_" + item.key + ")");
    } else {
    let m = item.uri.match(/http:\/\/zotero\.org\/(users|groups)\/([^\/]+)\/items\/(.+)/);
    let prefix;
    let lib;
    let key;
    if (m) {
    if (m[1] === "users") {
    prefix = "zu:";
    if (m[2] === "local") {
    lib = "0";
    } else {
    lib = m[2];
    }
    } else {
    prefix = "zg:";
    lib = m[2];
    }
    } else {
    prefix = "zu:";
    lib = "0";
    }
    Zotero.write(prefix + lib + ":" + item.key + "}");
    }
    }
    }
  • This is exactly what I want to do!

    But there's something I don't quite get - what does this do? Does it give you access to the URI in a custom citation? Or does it somehow let you write out a citation/reference in a different way?

    Thanks,
    Chris
Sign In or Register to comment.