我知道可以通过执行以下操作来使用 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 新闻格式中还有一个链接添加类型,我认为它应该以类似于内联文本样式的方式工作,内联文本样式放置在如下所示的组件中:
{
"role": "title",
"text": "My First Article",
"textStyle": "titleStyle",
"inlineTextStyles": [{
"rangeStart": 3,
"rangeLength": 5,
"textStyle": {
"textColor": "#FF00007F"
}
}
}
苹果提供了示例代码:
{
"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
相同的方式添加到组件中(因为文本块可以有多个链接,就像它可以有多个样式一样),但我无法获得这个或任何我尝试使用的变体。是不是新闻预览还不能渲染这个?
将其添加到组件内部的"additions"属性下,而不是在组件内部的"linkAdditions"下添加。
例如,这应该有效:
...
"role": "body",
"text": "Article text goes here and here",
"additions": [{
"type": "link",
"URL": "http://www.apple.com",
"rangeStart": 0,
"rangeLength": 20
}],
...
注意:如果格式为 markdown,它将忽略 additions 属性。