将此段代码替换AHKV2的内容,保存后运行即可
$$IsStyleExists(doc,name)
{
Loop doc.Styles.Count
{
style := doc.Styles.Item(A_Index)
if (style.NameLocal = name) {
return true
}
}
return false
}
ChangFieldColor(doc)
{
Loop doc.Fields.Count
{
field := doc.Fields.Item(A_Index)
r := field.Result
if (InStr(field.Code.Text, " ADDIN ZOTERO_ITEM") = 1) {
if (InStr(r.Text,"(")=1 or InStr(r.Text,"[")=1 or InStr(r.Text,"(")=1)
{
r.SetRange(r.Start + 1, r.End - 1)
} else {
pos:= RegExMatch(r.Text, "\(\d{4}\w?\)", &OutputVar)
if(pos>0)
{
r.SetRange(r.Start + pos, r.Start + pos + StrLen(OutputVar[])-2)
}
}
r.Style:="zoteroCitation"
}
}
return
}
citation := 'ADDIN ZOTERO_ITEM CSL_CITATION {Citations}'
Word := ComObjActive("Word.Application")
winactive("A")
doc := Word.ActiveDocument
Word.ScreenUpdating := False
doc.Fields.Add(Word.Selection.Range, 17, citation, true)
Word.Run("Zotero.ZoteroRefresh")
Sleep 1000
if(!IsStyleExists(doc,"zoteroCitation")){
doc.Styles.Add("zoteroCitation", 2)
doc.Styles["zoteroCitation"].Font.ColorIndex := 2
}
ChangFieldColor(doc)
Word.ScreenUpdating := true
收到,最近很忙,闲下来处理。最好能提供调试报告。