2

我有一个类型的对象block来获得一个所见即所得的编辑器。它看起来像这样:

{
  title: "Block",
  type: "block",

  styles: [
    { title: "Normal", value: "normal" },
    { title: "H1", value: "h1" },
    { title: "H2", value: "h2" },
    { title: "H3", value: "h3" },
    { title: "H4", value: "h4" },
    { title: "Quote", value: "blockquote" }
  ],
  lists: [{ title: "Bullet", value: "bullet" }],
  marks: {
    decorators: [
      { title: "Strong", value: "strong" },
      { title: "Emphasis", value: "em" }
    ],
    annotations: [
      {
        title: "URL",
        name: "link",
        type: "object",
        fields: [
          {
            title: "URL",
            name: "href",
            type: "url"
          }
        ]
      }
    ]
  }
}

但我看不到可以选择文本颜色的选项。有没有办法启用它?也许是插件?

4

1 回答 1

2

确实有一个插件。在您的终端中,cd到您的 Sanity Content Studio 文件夹,然后运行:

sanity install @sanity/color-input

这将附加@sanity/color-inputpluginssanity.json 文件中的数组并在本地安装@sanity/color-inputnpm 包。

然后,继续将color类型添加到annotations要启用文本颜色的块内容中的数组中。例如:

export default {
  name: 'blockContent',
  type: 'array',
  title: 'Block Content with Color',
  of: [
    {
      type: 'block',
      marks: {
        annotations: [
          {name: 'color', title: 'Color', type: 'color'}
        ]
      }
    }
  ]
}

另外,请记住,您现在将获得带有颜色细节注释的文本。您的前端如何(以及是否)选择呈现结构化文本取决于您。

于 2018-11-26T08:45:52.960 回答