gpt4 book ai didi

html - InDesign 脚本更改文本框中的子字符串样式

转载 作者:太空宇宙 更新时间:2023-11-03 23:26:50 26 4
gpt4 key购买 nike

我想构建一个 InDesign 脚本,当您导入 html 标签(例如粗体和斜体)时,这些词会转换为粗体或斜体。

例如

I really like <strong>walking to the park</strong> and eating icecream会是:

我真的很喜欢步行去公园和吃冰淇淋。

但是,在我的文本框中,我只能获取整个段落来选择一种样式,而不是单个单词或短语。

在下面的示例中,我想将粗体样式应用于 secondPhrase 变量(我没有问题剥离标签等 - 只是想知道如何将样式应用于 secondPhrase

with (myElement) {

// Apply basic text style
applyParagraphStyle(myDoc.paragraphStyles.item("DefaultText"));

var firstPhrase = "I really like";
var secondPhrase = " walking to the park";
var thirdPhrase = " and eating icecream";

contents = firstLine + secondLine + thirdPhrase;

}

最佳答案

类似下面的代码应该可以解决问题。 insertionPoint 就像 InDesign 中的光标一样。如果您一直捕获最后一个 insertionPoint,您可以在添加文本时更改它的样式。

var doc = app.documents.add();

var frame = doc.pages[0].textFrames.add({
geometricBounds: [6, 6, 40, 40]
});

var bold = doc.characterStyles.add({ name: "Bold", fontStyle: "Bold" });
var none = doc.characterStyles.itemByName("[None]");

frame.insertionPoints.lastItem().applyCharacterStyle(none);

frame.insertionPoints.lastItem().contents = "I really like";

frame.insertionPoints.lastItem().applyCharacterStyle(bold);

frame.insertionPoints.lastItem().contents = " walking to the park";

frame.insertionPoints.lastItem().applyCharacterStyle(none);

frame.insertionPoints.lastItem().contents = " and eating icecream";

关于html - InDesign 脚本更改文本框中的子字符串样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26628968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com