Handle SVG files in markdown
This commit is contained in:
parent
8a264b141b
commit
7fe1865dfd
@ -4,6 +4,9 @@ import Splash
|
||||
|
||||
struct PageContentGenerator {
|
||||
|
||||
#warning("Specify page image width in configuration")
|
||||
let pageImageWidth = 748
|
||||
|
||||
private let factory: TemplateFactory
|
||||
|
||||
private let files: FileProcessor
|
||||
@ -75,17 +78,16 @@ struct PageContentGenerator {
|
||||
case .video:
|
||||
return try handleVideo(page: page, file: file, optionString: alt)
|
||||
case .file:
|
||||
#warning("Handle other files in markdown")
|
||||
print("[WARN] Unhandled file \(file) with extension \(fileExtension)")
|
||||
return ""
|
||||
if fileExtension == "svg" {
|
||||
return try handleSvg(page: page, file: file)
|
||||
}
|
||||
return try handleFile(page: page, file: file, fileExtension: fileExtension)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleImage(page: Page, file: String, rightTitle: String?, leftTitle: String?) throws -> String {
|
||||
let imagePath = page.pathRelativeToRootForContainedInputFile(file)
|
||||
|
||||
#warning("Specify page image width in configuration")
|
||||
let pageImageWidth = 748
|
||||
let size = try files.requireImage(source: imagePath, destination: imagePath, width: pageImageWidth)
|
||||
|
||||
let imagePath2x = imagePath.insert("@2x", beforeLast: ".")
|
||||
@ -122,4 +124,21 @@ struct PageContentGenerator {
|
||||
files.require(file: filePath)
|
||||
return factory.video.generate(sources: sources, options: options)
|
||||
}
|
||||
|
||||
private func handleSvg(page: Page, file: String) throws -> String {
|
||||
let imagePath = page.pathRelativeToRootForContainedInputFile(file)
|
||||
files.require(file: imagePath)
|
||||
|
||||
return """
|
||||
<span class="image">
|
||||
<img src="\(file)"/>
|
||||
</span>
|
||||
"""
|
||||
}
|
||||
|
||||
private func handleFile(page: Page, file: String, fileExtension: String) throws -> String {
|
||||
#warning("Handle other files in markdown")
|
||||
print("[WARN] Unhandled file \(file) with extension \(fileExtension)")
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user