Leaf Markdown

Language Build Status codecov GitHub license

一个用于 Vapor 和 Leaf 的 Markdown 渲染器。它使用 Vapor Markdown 包裹 cmark (尽管使用了一个 fork 版本以使其能在 Swift PM 中工作),因此它理解 Common Mark。Common Mark 的快速参考指南可以在 这里 找到。它也支持 Github Flavored Markdown

用法

一旦设置完成,你就可以在你的 Leaf 模板文件中使用它,像其他任何标签一样

#markdown(myMarkdown)

在你将 myMarkdown 传递到视图中,像这样

# Hey #

Check out my *awesome* markdown! It is easy to use in `tags`

设置

添加为依赖

在你的 Package.swift 文件中添加 Leaf Markdown 作为依赖项

    dependencies: [
        ...,
        .package(name: "LeafMarkdown", url: "https://github.com/vapor-community/leaf-markdown.git", .upToNextMajor(from: "3.0.0")),
    ]

然后将依赖项添加到你的目标

.target(
    name: "App",
    dependencies: [
        // ...
        "LeafMarkdown"
    ],
    // ...
)

向 Leaf 注册

向 Leaf 注册标签,以便 Leaf 知道它

app.leaf.tags["markdown"] = Markdown()

不要忘记在你注册标签的文件中导入 LeafMarkdown,例如:import LeafMarkdown