欢迎光临散文网 会员登陆 & 注册

zotero-javascripts文章题目大小写转为每个单词首字母大写-

2023-08-17 23:01 作者:SWNTs  | 我要投稿

zoteroPane = Zotero.getActiveZoteroPane();

items = zoteroPane.getSelectedItems();

var result = "";


// 列出常见的介词

var prepositions = ["of", "in", "on", "and", "the", "with", "for", "to", "at", "by", "from"];


for (item of items) {

    var title = item.getField('title');

    result += " " + title + "\n";

    

    var new_title = title.replace(/\b\w+\b/g, function (word) {

        if (prepositions.includes(word.toLowerCase())) {

            return word.toLowerCase();

        } else {

            return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();

        }

    });

    

    result += "-> " + new_title + "\n\n";

    

    // Do it at your own risk

    item.setField('title', new_title);

    await item.saveTx();

}


return result;


        陈  林 

2023年8月17日 上海 FDU


参考资料:

https://www.zotero.org/support/dev/client_coding/javascript_api

https://github.com/redleafnew/zotero-javascripts/blob/main/02change-the-item-title-to-sentence-case.js

https://chat.openai.com/




zotero-javascripts文章题目大小写转为每个单词首字母大写-的评论 (共 条)

分享到微博请遵守国家法律