John Sundell 8e7599150f
Add SplashMarkdown (#57)
This change adds a new command line tool to the Splash family:
`SplashMarkdown`.

It’s an adapted version of the tool that I’ve been using for months to
publish every article on Swift by Sundell, and works by replacing all
code blocks within a Markdown file.

Adding this will hopefully make Splash even easier to use, without the
need for writing custom tooling, or to manually replace each code block
within a Markdown file with a “splashed” version.
2019-03-15 20:24:53 +01:00

34 lines
715 B
Swift

/**
* Splash
* Copyright (c) John Sundell 2019
* MIT license - see LICENSE.md
*/
import Foundation
import Splash
guard CommandLine.arguments.count > 1 else {
print("⚠️ Please supply the path to a Markdown file to process as an argument")
exit(1)
}
let markdown: String = {
let path = CommandLine.arguments[1]
do {
let path = (path as NSString).expandingTildeInPath
return try String(contentsOfFile: path)
} catch {
print("""
🛑 Failed to open Markdown file at '\(path)':
---
\(error.localizedDescription)
---
""")
exit(1)
}
}()
let decorator = MarkdownDecorator()
print(decorator.decorate(markdown))