突出显示所有脚注上标

问题描述 投票:0回答:1

我想要一种方法来突出显示所有表示脚注的上标,以便在用眼睛浏览时更容易看到段落中的脚注。目标是这样的:

我找不到任何手动执行此操作的方法,也找不到任何可以为我执行此操作的附加组件。有没有办法用脚本来做到这一点?

我在这里尝试了答案Google脚本:与脚注交互,但它改变了脚注的样式主体,而不改变上标数字本身的样式。我希望能够一次性格式化上标,但与脚注主体分开。

google-apps-script google-docs google-docs-api footnotes
1个回答
0
投票

不幸的是,我在Google文档服务(DocumentApp)中找不到管理脚注上标数字样式的方法。我担心现阶段Google文档服务的方法中可能没有直接改变脚注上标数字的方法。但是,幸运的是,我认为当使用 Google Docs API 时,你的目标就可以实现。在这个答案中,我想提出一个使用 Docs API 的示例脚本。

示例脚本:

在使用此脚本之前,请在高级 Google 服务中启用 Google Docs API

function myFuction() {
  const doc = DocumentApp.getActiveDocument();
  const docId = doc.getId();
  const obj = Docs.Documents.get(docId);
  const requests = obj.body.content.reduce((ar, e) => {
    if (e.paragraph) {
      e.paragraph.elements.forEach(f => {
        if (f.footnoteReference) {
          ar.push({ updateTextStyle: { textStyle: { backgroundColor: { color: { rgbColor: { red: 0, green: 1, blue: 0 } } } }, range: { startIndex: f.startIndex, endIndex: f.endIndex }, fields: "backgroundColor" } });
        }
      });
    }
    return ar;
  }, []);
  if (requests.length == 0) return;
  Docs.Documents.batchUpdate({ requests }, docId);
}

测试:

运行该脚本,得到以下结果。

注:

  • 在此示例中,它假设从您显示的图像中仅检查段落。如果除段落之外的其他部分存在脚注的上标编号,请修改上面的脚本。

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.