InDesign:如何获得带有characterStyles的段落内容? [英] InDesign: How can I get paragraph contents with its characterStyles?

查看:244
本文介绍了InDesign:如何获得带有characterStyles的段落内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为InDesign编写一个非常自定义的导出脚本(我拥有CC 9.2,但我的目标是CS6)。

I'm trying to write a very custom export script for InDesign (I have CC 9.2, but my target is CS6).

当我处理一个段落时,我可以得到它的段落样式及其内容。我不明白的是:如何获得内容内容的characterStyles?

When I process a paragraph, I can get its paragraphStyle and its content. What I don't understand is: how can I get the content and the characterStyles of the content?

我正在查看文档,但是我不明白如何才能进入一个段落并找到所有characterStyles及其应用的文本部分。

I'm looking at the docs, but I don't understand how can I descend into a paragraph and find all characterStyles and the text parts to which they are applied.

例如,如果我有如下所示的段落:

If, for instance, I have a paragraph like the following:


我的 nice 段落。

我想知道我的 段落。 具有style1,而 nice 具有style2。

I want to know that "My " and " paragraph." have style1, while "nice" have style2.

最终结果应类似于:

[
  {
    text: "My ",
    style: "style1"
  },
  {
    text: "Nice",
    style: "style2"
  },
  {
    text: " paragraph.",
    style: "style1"
  }
]

如何获取

推荐答案

使用段落的 TextStyleRange 属性。

Use the TextStyleRange property of a paragraph.

TextStyleRange是具有相同格式的单个连续文本范围。对于InDesign而言,格式是本地格式还是通过字符样式应用都无所谓。

A TextStyleRange is one single continuous range of text with the same formatting. It does not matter to InDesign whether the formatting is 'local' or applied through a character style.

必不可少的警告:


  1. TextStyleRanges参见 all 本地格式,无论是否通过Char样式应用。

  2. TextStyleRange格式看不到GREP样式

  3. 段落中的最后一个文本范围可能(通常)愉快地包含最终的返回值以及任何和所有 >以下段落中的文本仍然具有完全相同的格式。如果按段落检索textStyleRanges,请在返回段落后检查每个返回的文本内容是否存在文本。如果确实包含段落返回,则可以选择剪掉多余的文本,然后退出当前段落的循环。

  1. TextStyleRanges see all local formatting, whether or not applied through a Char Style.
  2. TextStyleRange formatting does not see GREP styles.
  3. The last text range in a paragraph may (and usually will) happily contain the final return, as well as any and all text in following paragraphs that still have the exact same formatting. If you retrieve textStyleRanges per paragraph, check each returned text contents for the presence of text after a paragraph return. If it does contain a paragraph return, optionally clip off the excess text, and exit the loop for the current paragraph.

最小示例代码:

tsr = app.selection[0].paragraphs[0].textStyleRanges;

text = [];
for (i=0; i<tsr.length; i++)
    text.push ('text: "'+tsr[i].contents+'", style: "'+tsr[i].appliedCharacterStyle.name+'"');
alert (text.join ('\r'));

这篇关于InDesign:如何获得带有characterStyles的段落内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆