如何在不使用降价的情况下使用Apple新闻格式的链接添加(超链接)?

时间:2016-03-22 11:50:52

标签: ios json format apple-news

我知道可以通过执行以下操作,使用markdown在Apple News Format文章中包含超链接:

{
    "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类型,我认为它应该以与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
}

但它没有像其他元素那样给出任何放置位置的说明。它具有“类型”键也是相当神秘的,这与其他元素不同。不仅如此,在类型描述中它被全部大写地描述为LinkAddition。我尝试了各种组合,其中最明显的是我猜想

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

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

1 个答案:

答案 0 :(得分:2)

在"添加"下添加它属性而不是" linkAdditions"在你想要的组件内部。

例如,这应该有效:

...

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

...

注意:如果格式为markdown,则会忽略additions属性。