【问题标题】:Sanity.io code input – how to add an input field for highlighted lines?Sanity.io 代码输入 - 如何为突出显示的行添加输入字段?
【发布时间】:2021-01-24 07:14:57
【问题描述】:

我一直在尝试将 highlightedLines 字段添加到 Sanity.io 代码输入。我发现的唯一文档在模块的npm page 上,并且有一个示例数据模型:

{
  _type: 'code',
  language: 'js',
  highlightedLines: [1, 2], // <--- I need to have this field accessible in sanity studio
  code: 'const foo = "bar"\nconsole.log(foo.toUpperCase())\n// BAR'
}

我尝试(天真地)将fields: { foo: "array" } 属性添加到blockContent.js 中的“代码块”对象,但随后工作室没有编译,抛出Cannot override 'fields' of subtypes of "object" 错误。

我是否需要从code 创建新类型并分别用其他字段装饰它?

// current blockContent.js

export default {
  title: "Block Content",
  name: "blockContent",
  type: "array",
  of: [
    {
    // ...  

    {
      type: "image",
      options: { hotspot: true },
    },
    {
      title: "Code block",
      name: "code",
      type: "code",
      options: {
        withFilename: true,
      }
    },
  ],
};

我很乐意接受任何建议。

【问题讨论】:

    标签: javascript user-input sanity


    【解决方案1】:

    您可以通过单击左侧的行号来突出显示该行。可以添加到文档中:)

    【讨论】:

    • 太棒了!我永远也想不通。确实应该在文档中提及。
    猜你喜欢
    • 1970-01-01
    • 2013-02-21
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 2015-05-23
    • 1970-01-01
    相关资源
    最近更新 更多