A templating engine for Kitura that uses Markdown-based templates.
Kitura-Markdown enables a Kitura server to serve HTML content generated from Markdown templates (.md files).
Markdown File
Markdown is a lightweight markup language with plain text formatting syntax. Mastering Markdown provides documentation and examples on how to write Markdown files. By default the Kitura Router will look in the Views folder for Markdown files with the extension .md.
Usage
Add dependencies
Add the Kitura-Markdown package to the dependencies within your application’s Package.swift file. Substitute "x.x.x" with the latest Kitura-Markdownrelease.
The Views folder and Example.md file will be created later on, since they are not initialized by kitura init.
Dependencies
Add the dependencies to your Package.swift file (as defined in Add dependencies above).
Application.swift
Inside the Application.swift file, add the following code to render the Example.md template file on the “/docs” route.
import KituraMarkdown
Add the following code inside the postInit() function:
router.add(templateEngine: KituraMarkdown())
router.get("/docs") { _, response, next in
try response.render("Example.md", context: [String:Any]())
response.status(.OK)
next()
}
Example.md
Create the Views folder and put the following Markdown template code into a file called Example.md:
It's very easy to make some words **bold** and other words *italic* with Markdown. You can even [link to Kitura](https://github.com/Kitura/Kitura) and write code examples:
`print("Hello world!")`
Kitura-Markdown
A templating engine for Kitura that uses Markdown-based templates.
Kitura-Markdown
enables a Kitura server to serve HTML content generated from Markdown templates (.md
files).Markdown File
Markdown is a lightweight markup language with plain text formatting syntax. Mastering Markdown provides documentation and examples on how to write Markdown files. By default the Kitura Router will look in the
Views
folder for Markdown files with the extension.md
.Usage
Add dependencies
Add the
Kitura-Markdown
package to the dependencies within your application’sPackage.swift
file. Substitute"x.x.x"
with the latestKitura-Markdown
release.Add
KituraMarkdown
to your target’s dependencies:Import package
Example
The following example takes a server generated using
kitura init
and modifies it to serve Markdown-formatted text from a.md
file.The files which will be edited in this example, are as follows:
The
Views
folder andExample.md
file will be created later on, since they are not initialized bykitura init
.Dependencies
Add the dependencies to your Package.swift file (as defined in Add dependencies above).
Application.swift
Inside the
Application.swift
file, add the following code to render theExample.md
template file on the “/docs” route.Add the following code inside the
postInit()
function:Example.md
Create the
Views
folder and put the following Markdown template code into a file calledExample.md
:When the server is running, go to http://localhost:8080/docs to view the rendered Markdown template.
API documentation
For more information visit our API reference.
Community
We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!
License
This library is licensed under Apache 2.0. Full license text is available in LICENSE.