从看起来像的 Google Doc 开始:
* Item
我希望进行一系列 API 调用以将文档转换为:* Item
- Subitem
但是,我不知道如何使用 API 做到这一点。 CreateParagraphBulletRequest
没有我可以指定的缩进级别。文档建议:The nesting level of each paragraph will be determined by counting leading tabs in front of each paragraph. To avoid excess space between the bullet and the corresponding paragraph, these leading tabs are removed by this request. This may change the indices of parts of the text.
但是,将制表符添加到
InsertTextRequest
的开头将在制表符之前添加,而不是更改缩进:* Item
* Subitem
有没有人对我可能做错的事情有任何想法?
最佳答案
我相信你的目标如下。
- item1
- item1
- item2
实现目标的要点:
在这种情况下,为了将项目插入到现有列表中作为第 2 级,根据我的经验,我无法直接插入它。就我而言,作为一种解决方法,我使用以下流程。
\n\titem2\n
第二级使用 insertText
要求。createParagraphBullets
,它将项目符号提供给列表。至此,\t
转换为嵌套项。 示例请求正文:
当上面的流程反射(reflect)到Docs API中batchUpdate方法的请求体时,就变成了这样。
{
"requests": [
{
"insertText": {
"text": "\n\titem2\n",
"location": {
"index": 7
}
}
},
{
"createParagraphBullets": {
"range": {
"startIndex": 1,
"endIndex": 15
},
"bulletPreset": "BULLET_DISC_CIRCLE_SQUARE"
}
},
{
"deleteParagraphBullets": {
"range": {
"startIndex": 7,
"endIndex": 8
}
}
},
{
"deleteContentRange": {
"range": {
"startIndex": 7,
"endIndex": 8
}
}
}
]
}
结果:当使用上述请求体时,得到如下结果。
前:
后:
笔记:
\t
从第一级提供项目。 .不幸的是,我不确定这是否是规范。那么,例如,如何为问题跟踪器请求这个作为 future 的请求? Ref 引用:
关于google-docs-api - 如何使用 Google Docs API 缩进项目符号列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65330602/