KituraMarkdown
public class KituraMarkdown : TemplateEngine
A Kitura TemplateEngine
that enables a Kitura server to render HTML content generated from Markdown
templates (.md files).
This class also provides helper methods for converting Markdown formatted text
from a String or Data to HTML.
Note
Under the covers this templating engine uses the cmark C language reference implementation of Markdown.Usage Example:
router.add(templateEngine: KituraMarkdown())
router.get("/docs") { _, response, next in
try response.render("Example.md", context: [String:Any]())
response.status(.OK)
next()
}
-
The file extension of files that will be rendered by the KituraMarkdown template engine. By default, Kitura will search for these in the
./Views/directory, which can be customized by setting therouter.viewsPathproperty.Declaration
Swift
public let fileExtension: String -
Create a
KituraMarkdowninstance that can be registered with a Kitura router.Declaration
Swift
public init() -
Take a template file in Markdown format and generate HTML format content to be sent back to the client.
Throws
An error if the template file cannot be read.Declaration
Swift
public func render(filePath: String, context: [String : Any]) throws -> StringParameters
filePathThe path of the template file in Markdown format to use when generating the content.
contextA set of variables in the form of a Dictionary of Key/Value pairs. Note: This parameter is ignored at this time.
Return Value
A String containing an HTML representation of the text marked up using Markdown.
-
Take a template file in Markdown format and generate HTML format content to be sent back to the client.
Note that rendering of context is not supported at this time, and the
withandforKeyparameters are currently ignored.Throws
An error if the template file cannot be read.Declaration
Swift
public func render<T>(filePath: String, with: T, forKey: String?, options: RenderingOptions, templateName: String) throws -> String where T : EncodableParameters
filePathThe path of the template file in Markdown format to use when generating the content.
withA value that conforms to Encodable. Note: This parameter is ignored at this time.
forKeyA value used to match the Encodable values to the correct variable in a template file. Note: This parameter is ignored at this time.
optionsA
RenderingOptionsused to customize the output. The HTML page template can be customized by providing an instance ofMarkdownOptions.Return Value
A String containing an HTML representation of the text marked up using Markdown.
-
Take a template file in Markdown format and generate HTML format content to be sent back to the client.
Note that rendering of context is not supported at this time, and the
contextparameter is currently ignored.Throws
An error if the template file cannot be read.Declaration
Swift
public func render(filePath: String, context: [String: Any], options: RenderingOptions) throws -> StringParameters
filePathThe path of the template file in Markdown format to use when generating the content.
contextA set of variables in the form of a Dictionary of Key/Value pairs. Note: This parameter is ignored at this time
optionsA
RenderingOptionsused to customize the output. The HTML page template can be customized by providing an instance ofMarkdownOptions.Return Value
A String containing an HTML representation of the text marked up using Markdown.
-
Generate HTML content from a Data struct containing text marked up in Markdown in the form of UTF-8 bytes.
Declaration
Swift
public static func render(from: Data) -> StringParameters
fromThe Data struct containing markdown text in UTF-8.
Return Value
A String containing an HTML representation of the text marked up using Markdown.
-
Generate HTML content from a String containing text marked up in Markdown.
Declaration
Swift
public static func render(from: String) -> StringParameters
fromThe String containing markdown text in UTF-8.
Return Value
A String containing an HTML representation of the text marked up using Markdown.
-
Generate an HTML page from a String containing text marked up in Markdown.
Declaration
Swift
public static func render(from: String, pageTemplate: String) -> StringParameters
fromThe String containing markdown in UTF-8.
pageTemplateThe HTML page template to use. The page template should contain
<snippetInsertLocation></snippetInsertLocation>, which will be substituted with the generated HTML content. Note: If you do not wish to customize the page template,"default"can be specified.Return Value
A String containing an HTML representation of the text marked up using Markdown, enclosed in an HTML page corresponding to the
pageTemplatesupplied.
View on GitHub
KituraMarkdown Class Reference