A Markdown parser for Swift Package Manager, using Github Flavored Markdown. As such it comes with a bunch of Markdown extensions such as fenced code blocks, tables, strikethrough, hard line breaks and auto links.
Additionally Parsley supports embedded metadata in Markdown documents, and it splits the document title out from the document body.
let input = """
---
author: Kevin
tags: Swift, Parsley
---
# Hello World
This is the body
"""
let document = try Parsley.parse(input)
print(document.title) // Hello World
print(document.body) // <p>This is the body</p>
print(document.metadata) // ["author": "Kevin", "tags": "Swift, Parsley"]Parsley is available via Swift Package Manager and runs on macOS and Linux.
.package(url: "https://github.com/loopwerk/Parsley", from: "0.5.0"),
Parsley can be used as a reader in the static site generator Saga, using SagaParsleyMarkdownReader.
Parsley supports adding a title (typically a filename) to fenced code blocks using the title="..." syntax:
```python title="views.py"
def hello():
print("Hello, World!")
```This generates HTML with a data-title attribute on the <pre> element:
<pre data-title="views.py"><code class="language-python">def hello():
print("Hello, World!")
</code></pre>You can then use CSS to display the title, for example:
pre[data-title]::before {
content: attr(data-title);
display: block;
background: #1a1a1a;
padding: 0.5em 1em;
font-size: 0.85em;
border-bottom: 1px solid #333;
}Parsley doesn't come with a plugin system, it relies purely on cmark-gfm under the hood to render Markdown to HTML. If you want to modify the generated HTML, for example if you want to add target="blank" to all external links, SwiftSoup is a great way to achieve this.
If you want to add syntax highlighting to the code blocks, you could use a client-side JavaScript library such as Prism or highlight.js. Or for a server-side solution, check out Moon, which runs Prism in Swift.
