Compare commits
2 Commits
89245f2553
...
6e717a8cf7
Author | SHA1 | Date | |
---|---|---|---|
|
6e717a8cf7 | ||
|
87d54788db |
@ -67,10 +67,21 @@ extension String {
|
|||||||
|
|
||||||
extension Substring {
|
extension Substring {
|
||||||
|
|
||||||
|
func dropBeforeFirst(_ separator: String) -> String {
|
||||||
|
guard contains(separator) else {
|
||||||
|
return String(self)
|
||||||
|
}
|
||||||
|
return components(separatedBy: separator).dropFirst().joined(separator: separator)
|
||||||
|
}
|
||||||
|
|
||||||
func between(_ start: String, and end: String) -> String {
|
func between(_ start: String, and end: String) -> String {
|
||||||
components(separatedBy: start).last!
|
components(separatedBy: start).last!
|
||||||
.components(separatedBy: end).first!
|
.components(separatedBy: end).first!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func between(first: String, andLast last: String) -> String {
|
||||||
|
dropBeforeFirst(first).dropAfterLast(last)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
|
@ -87,8 +87,11 @@ struct PageContentGenerator {
|
|||||||
// For a simple boxes: ![box](title;body)
|
// For a simple boxes: ![box](title;body)
|
||||||
// A fancy page link: ![page](page_id)
|
// A fancy page link: ![page](page_id)
|
||||||
// External pages: ![external](url1, text1; url2, text2, ...)
|
// External pages: ![external](url1, text1; url2, text2, ...)
|
||||||
let fileAndTitle = markdown.between("(", and: ")")
|
guard let fileAndTitle = markdown.between(first: "](", andLast: ")").removingPercentEncoding else {
|
||||||
let alt = markdown.between("[", and: "]").nonEmpty
|
results.warning("Invalid percent encoding for markdown image", source: page.path)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
let alt = markdown.between("[", and: "]").nonEmpty?.removingPercentEncoding
|
||||||
if let alt = alt, let command = ShorthandMarkdownKey(rawValue: alt) {
|
if let alt = alt, let command = ShorthandMarkdownKey(rawValue: alt) {
|
||||||
return handleShortHandCommand(command, page: page, language: language, content: fileAndTitle)
|
return handleShortHandCommand(command, page: page, language: language, content: fileAndTitle)
|
||||||
}
|
}
|
||||||
@ -250,7 +253,7 @@ struct PageContentGenerator {
|
|||||||
.compactMap { button -> (file: String, text: String, downloadName: String?)? in
|
.compactMap { button -> (file: String, text: String, downloadName: String?)? in
|
||||||
let parts = button.components(separatedBy: ",")
|
let parts = button.components(separatedBy: ",")
|
||||||
guard parts.count == 2 || parts.count == 3 else {
|
guard parts.count == 2 || parts.count == 3 else {
|
||||||
results.warning("Invalid button definition", source: page.path)
|
results.warning("Invalid download definition with \(parts)", source: page.path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let file = parts[0].trimmed
|
let file = parts[0].trimmed
|
||||||
|
Loading…
Reference in New Issue
Block a user