ldstreet/playdocs
PlayDocs is command line tool for converting Swift Playgrounds to Markdown and HTML. Playgrounds have supported rendering markdown from the beginning, so why not leverage that for generating documentation that can live both in your repository as executable code and on your wiki o
π‘ Overview
PlayDocs is command line tool for converting Swift Playgrounds to Markdown and HTML. Playgrounds have supported rendering markdown from the beginning, so why not leverage that for generating documentation that can live both in your repository as executable code and on your wiki or blog as documention or a post?
βοΈ Usage
You can use PlayDocs both as a commandline tool or as a framework in your own code.
As a commandline tool...
Convert
Here is the basic command for generating a markdown file via a Playground:
playdocs convert ./MyPlayground.playground --openAnd if you want it to output as html:
playdocs convert ./MyPlayground.playground --html --openTo specify a destination:
playdocs convert ./MyPlayground.playground --destination /path/to/file/MyFile.md --openNew
PlayDocs can also help you easily create new Playground files so you can get your doc started fast:
playdocs new HelloPlayDocs --openIf you want the Playground to target MacOS:
playdocs new HelloPlayDocs --macos --openAnd if you don't want any boilerplate in your Playground:
playdocs new HelloPlayDocs --macos --empty --openAs a package...
To make your conversions in swift, you can use PlayDocsKit
// Convert swift source from a swift source string to a markdown string
public func convertToMarkdown(from source: SwiftSource) -> MarkdownSource
// Convert swift source from a file to a markdown file
public func convertToMarkdown(from source: URL, to destination: URL) throws
// Convert swift source from a string to an html string
public func convertToHTML(from source: SwiftSource) throws -> HTMLSource
// Convert swift source from a file to a html file
public func convertToHTML(from source: URL, to destination: URL) throws
// Custom conversion allowing caller to convert each Chunk as seen fit
public func convert(from source: SwiftSource, prepending header: String = "", appending footer: String = "", conversion convert: (Chunk) -> String) -> Stringπ Syntax Highlighting
Syntax highlighting for all Swift code is applied via John Sundell's Splash
Note: For now, the theme for syntax highlighting is hardcoded, but in the future this project should make the theme configurable.
β¬οΈ Installing
To install the commandline tool:
π± Mint
$ mint install ldstreet/PlayDocsπ§ Make
Run in terminal:
git clone https://github.com/ldstreet/PlayDocs.git && cd PlayDocs && make installπββοΈ Marathon
Add to your Marathonfile:
marathon add https://github.com/ldstreet/PlayDocs.gitOr use the inline dependency syntax:
import PlayDocsKit // https://github.com/ldstreet/PlayDocs.gitπ Swift Package Manager
To use PlayDocsKit add the following to your Package.swift file.
// π A framework for converting Playgrounds and Swift files to markdown and html
.package(url: "https://github.com/ldstreet/PlayDocs.git", from: "0.1.0"),
.target(name: "MyPackage", dependencies: ["PlayDocsKit"]),Package Metadata
Repository: ldstreet/playdocs
Default branch: master
README: README.md