如何在不使用 markdown 的情况下使用 Apple News 格式的 Link 添加(超链接)?

How do I use a Link Addition (hyperlink) in Apple News Format without using markdown?

我知道可以通过执行以下操作在使用 markdown 的 Apple 新闻格式文章中包含超链接:

{
    "version": "1.0",
    "identifier": "sketchyTech_Demo",
    "title": "My First Article",
    "language": "en",
    "layout": {},
    "components": [
        {
            "role": "title",
            "text": "My First Article",
            "textStyle": "titleStyle"
        },
        {
            "role": "body",
            "format": "markdown",
            "text": "Here's a [hyperlink](http://sketchytech.blogspot.co.uk).",
            "textStyle": "bodyStyle"
        }
    ],
    "componentTextStyles": {
        "titleStyle": {
            "textAlignment": "center",
            "fontName": "HelveticaNeue-Bold",
            "fontSize": 64,
            "lineHeight": 74,
            "textColor": "#000"
        },
        "bodyStyle": {
            "textAlignment": "left",
            "fontName": "Georgia",
            "fontSize": 18,
            "lineHeight": 26,
            "textColor": "#000"
        }
    }
}

但在 Apple News Format 中还有一个 Link Addition type, which I presume should work in a similar way to inline text styles,它们被放置在这样一个组件中:

    {
        "role": "title",
        "text": "My First Article",
        "textStyle": "titleStyle",
        "inlineTextStyles": [{
            "rangeStart": 3,
            "rangeLength": 5,
            "textStyle": {
                "textColor": "#FF00007F"
            }
        }
    }

Apple 提供示例代码:

{
  "type": "link",
  "URL": "http://www.apple.com",
  "rangeStart": 0,
  "rangeLength": 20
}

但是它没有像其他元素那样给出任何关于它应该放置在哪里的说明。比较神秘的是它有一个 "type" 键,这与其他元素不同。不仅如此,在类型描述中它被描述为全大写的 LinkAddition 。我尝试了各种组合,我猜其中最明显的组合是

"linkAdditions": [{
  "type": "link",
  "URL": "http://www.apple.com",
  "rangeStart": 0,
  "rangeLength": 20
}]

以与 inlineTextStyles 相同的方式添加到组件(因为文本块可以有多个链接,就像它可以有多种样式一样)但是我无法得到这个或我的任何变体试过工作。新闻预览可能还不能呈现这个吗?

将其添加到 "additions" 属性 下,而不是像您预期的那样添加到组件内部的 "linkAdditions" 下。

例如,这应该有效:

...

"role": "body",
"text": "Article text goes here and here",
"additions": [{
  "type": "link",
  "URL": "http://www.apple.com",
  "rangeStart": 0,
  "rangeLength": 20
}],

...

注意:如果格式是markdown,它将忽略添加属性。