Allow inclusion of html content
This commit is contained in:
parent
3d9551117d
commit
7354d6b58e
@ -79,11 +79,15 @@ struct PageContentGenerator {
|
|||||||
// External pages: ![external](url1, text1; url2, text2, ...)
|
// External pages: ![external](url1, text1; url2, text2, ...)
|
||||||
let fileAndTitle = markdown.between("(", and: ")")
|
let fileAndTitle = markdown.between("(", and: ")")
|
||||||
let alt = markdown.between("[", and: "]").nonEmpty
|
let alt = markdown.between("[", and: "]").nonEmpty
|
||||||
if alt == "download" {
|
switch alt {
|
||||||
|
case "download":
|
||||||
return handleDownloadButtons(page: page, content: fileAndTitle)
|
return handleDownloadButtons(page: page, content: fileAndTitle)
|
||||||
}
|
case "external":
|
||||||
if alt == "external" {
|
|
||||||
return handleExternalButtons(page: page, content: fileAndTitle)
|
return handleExternalButtons(page: page, content: fileAndTitle)
|
||||||
|
case "html":
|
||||||
|
return handleExternalHTML(page: page, file: fileAndTitle)
|
||||||
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = fileAndTitle.dropAfterFirst(" ")
|
let file = fileAndTitle.dropAfterFirst(" ")
|
||||||
@ -205,4 +209,18 @@ struct PageContentGenerator {
|
|||||||
}
|
}
|
||||||
return factory.html.externalButtons(buttons)
|
return factory.html.externalButtons(buttons)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func handleExternalHTML(page: Element, file: String) -> String {
|
||||||
|
let url = page.inputFolder.appendingPathComponent(file)
|
||||||
|
guard url.exists else {
|
||||||
|
log.add(error: "File \(file) not found", source: page.path)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
return try String(contentsOf: url)
|
||||||
|
} catch {
|
||||||
|
log.add(error: "File \(file) could not be read", source: page.path, error: error)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user