【问题标题】:Spaces in Swift's Markup LanguageSwift 标记语言中的空格
【发布时间】:2016-08-15 03:11:40
【问题描述】:

Swift 上的文档为标记中的 spacing Examples 提供了以下代码:

/*:
  - example: *A simple `for` loop.*\
  This example shows a `for` loop that prints the numbers 1 to 5.\
    \
     `for index in 1...5 {`\
     `   print("index = \(index)")`\
     `}`}
 */

在渲染的标记中没有出现空格:

如何在代码 sn-ps 中添加空格,尤其是在标记中自定义 callouts() 的示例?

【问题讨论】:

  • @tktsubota,我试过了,但有三次反勾号。不幸的是,这些对自定义 callouts() 没有帮助。
  • 您是否使用 Playgrounds 标记或代码文档?
  • @ronatory 代码在 Playground 中。

标签: swift documentation markup


【解决方案1】:

因此,要在您的代码示例中显示空格,请尝试按照您的示例进行操作:

/*:
A simple for loop.\
This example shows a for loop that prints the numbers 1 to 5.

    for index in 1...5 {
        print("index = \(index)")
    }
*/

结果在 Rendered Markup 中看起来像这样(空格出现在代码块中):

评论后编辑:

我发现的唯一方法是让您的前两行标记也在示例内部并且模拟空格是使用此代码(在打印行中,前两个反引号和它们之间的一个空格,然后在这八个空格之后直到打印的开始反引号):

/*:
- example: *A simple `for` loop.*\
This example shows a `for` loop that prints the numbers 1 to 5.\
\
`for index in 1...5 {`\
` `        `print("index = \(index)")`\
`}`}
*/

这会导致:

【讨论】:

  • 如果您将图像中的侧边栏与我的侧边栏进行比较,您会注意到前两行标记在示例之外。您的代码不会调用callout()
  • 更新了答案,但我真的不明白你打电话给callout()的意思
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-28
  • 2012-03-16
  • 1970-01-01
  • 2019-02-13
  • 1970-01-01
  • 2014-07-29
相关资源
最近更新 更多