Skip to content

Commit

Permalink
Make it work for macOS 10.11
Browse files Browse the repository at this point in the history
  • Loading branch information
trungdq88 committed Jul 29, 2021
1 parent 4db6cc5 commit 5d716a7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"object": {
"pins": [
{
"package": "cmark",
"package": "cmark-gfm",
"repositoryURL": "https://github.com/brokenhandsio/cmark-gfm.git",
"state": {
"branch": null,
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "Parsley",
platforms: [
.macOS(.v10_15)
.macOS(.v10_11)
],
products: [
.library(
Expand Down
26 changes: 3 additions & 23 deletions Sources/Parsley/Parsley.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public struct Parsley {

/// This parses a String into a Document, which contains parsed Metadata and the document title.
public static func parse(_ content: String, options: MarkdownOptions = [.safe]) throws -> Document {
let (header, title, rawBody) = Parsley.parts(from: content)
let rawBody = content

let metadata = Parsley.metadata(from: header)
let metadata = Parsley.metadata(from: "")
let bodyHtml = try Parsley.html(rawBody, options: options).trimmingCharacters(in: .newlines)

return Document(title: title, rawBody: rawBody, body: bodyHtml, metadata: metadata)
return Document(title: "", rawBody: rawBody, body: bodyHtml, metadata: metadata)
}
}

Expand Down Expand Up @@ -61,24 +61,4 @@ private extension Parsley {
return Dictionary(pairs) { a, _ in a }
}

/// Grabs the metadata (wrapped within `---`), the first title, and the body of the document.
static func parts(from content: String) -> (String?, String?, String) {
let scanner = Scanner(string: content)

var header: String? = nil
var title: String? = nil

if scanner.scanString("---") == "---" {
header = scanner.scanUpToString("---")
_ = scanner.scanString("---")
}

if scanner.scanString("# ") == "# " {
title = scanner.scanUpToString("\n")
}

let body = String(scanner.string[scanner.currentIndex...])

return (header, title, body)
}
}

0 comments on commit 5d716a7

Please sign in to comment.