-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from tatsuz0u/develop
Features & Bugfixes
- Loading branch information
Showing
61 changed files
with
1,397 additions
and
1,203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// MarkdownUtil.swift | ||
// EhPanda | ||
// | ||
// Created by 荒木辰造 on R 4/02/20. | ||
// | ||
|
||
import CasePaths | ||
import CommonMark | ||
import Foundation | ||
|
||
struct MarkdownUtil { | ||
static func parseTexts(markdown: String) -> [String] { | ||
(try? Document(markdown: markdown))?.blocks | ||
.compactMap((/Block.paragraph).extract) | ||
.flatMap(\.text) | ||
.compactMap((/Inline.text)) | ||
?? [] | ||
} | ||
static func parseLinks(markdown: String) -> [URL] { | ||
(try? Document(markdown: markdown))?.blocks | ||
.compactMap((/Block.paragraph).extract) | ||
.flatMap(\.text) | ||
.compactMap((/Inline.link)) | ||
.compactMap(\.url) | ||
?? [] | ||
} | ||
static func parseImages(markdown: String) -> [URL] { | ||
(try? Document(markdown: markdown))?.blocks | ||
.compactMap((/Block.paragraph).extract) | ||
.flatMap(\.text) | ||
.compactMap((/Inline.image)) | ||
.compactMap { image in | ||
if image.url?.absoluteString.isValidURL == true { | ||
return image.url | ||
} else if let title = image.title, title.isValidURL { | ||
return .init(string: title) | ||
} | ||
return nil | ||
} | ||
?? [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.