chriseidhof / commonmark-swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

markdownToHTML should return a non-optional string

ole opened this issue · comments

public func markdownToHTML(markdown: String) -> String? {
    let outString = cmark_markdown_to_html(markdown, markdown.utf8.count, 0)
    return String(UTF8String: outString)
}

I think this function should return a String instead. If you think about it, any text is valid Markdown, so the conversion can't really fail (or at least it shouldn't). The implementation currently returns nil if String(UTF8String: outString) fails, but this should never happen, either. We know cmark_markdown_to_html returns a valid null-terminated UTF-8 string, after all.

The same goes for the html, xml, commonMark, and latex properties on Node.

You are right!