Syntax highlight swift code

This commit is contained in:
Christoph Hagen 2022-08-18 08:49:01 +02:00
parent a444c51697
commit 8a264b141b
3 changed files with 31 additions and 2 deletions

View File

@ -54,6 +54,7 @@
E2F8FA2428ACD0A800632026 /* PageImageTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F8FA2328ACD0A800632026 /* PageImageTemplate.swift */; }; E2F8FA2428ACD0A800632026 /* PageImageTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F8FA2328ACD0A800632026 /* PageImageTemplate.swift */; };
E2F8FA2628ACD64500632026 /* PageVideoTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F8FA2528ACD64500632026 /* PageVideoTemplate.swift */; }; E2F8FA2628ACD64500632026 /* PageVideoTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F8FA2528ACD64500632026 /* PageVideoTemplate.swift */; };
E2F8FA2828ACD84400632026 /* VideoType.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F8FA2728ACD84400632026 /* VideoType.swift */; }; E2F8FA2828ACD84400632026 /* VideoType.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F8FA2728ACD84400632026 /* VideoType.swift */; };
E2F8FA2B28AD0BD200632026 /* Splash in Frameworks */ = {isa = PBXBuildFile; productRef = E2F8FA2A28AD0BD200632026 /* Splash */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
@ -124,6 +125,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
E22E878C289E4A8900E51191 /* Ink in Frameworks */, E22E878C289E4A8900E51191 /* Ink in Frameworks */,
E2F8FA2B28AD0BD200632026 /* Splash in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -273,6 +275,7 @@
name = WebsiteGenerator; name = WebsiteGenerator;
packageProductDependencies = ( packageProductDependencies = (
E22E878B289E4A8900E51191 /* Ink */, E22E878B289E4A8900E51191 /* Ink */,
E2F8FA2A28AD0BD200632026 /* Splash */,
); );
productName = WebsiteGenerator; productName = WebsiteGenerator;
productReference = E22E875F289D84C300E51191 /* WebsiteGenerator */; productReference = E22E875F289D84C300E51191 /* WebsiteGenerator */;
@ -304,6 +307,7 @@
mainGroup = E22E8756289D84C300E51191; mainGroup = E22E8756289D84C300E51191;
packageReferences = ( packageReferences = (
E22E878A289E4A8900E51191 /* XCRemoteSwiftPackageReference "ink" */, E22E878A289E4A8900E51191 /* XCRemoteSwiftPackageReference "ink" */,
E2F8FA2928AD0BD200632026 /* XCRemoteSwiftPackageReference "Splash" */,
); );
productRefGroup = E22E8760289D84C300E51191 /* Products */; productRefGroup = E22E8760289D84C300E51191 /* Products */;
projectDirPath = ""; projectDirPath = "";
@ -538,6 +542,14 @@
minimumVersion = 0.5.1; minimumVersion = 0.5.1;
}; };
}; };
E2F8FA2928AD0BD200632026 /* XCRemoteSwiftPackageReference "Splash" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/JohnSundell/Splash";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.16.0;
};
};
/* End XCRemoteSwiftPackageReference section */ /* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */ /* Begin XCSwiftPackageProductDependency section */
@ -546,6 +558,11 @@
package = E22E878A289E4A8900E51191 /* XCRemoteSwiftPackageReference "ink" */; package = E22E878A289E4A8900E51191 /* XCRemoteSwiftPackageReference "ink" */;
productName = Ink; productName = Ink;
}; };
E2F8FA2A28AD0BD200632026 /* Splash */ = {
isa = XCSwiftPackageProductDependency;
package = E2F8FA2928AD0BD200632026 /* XCRemoteSwiftPackageReference "Splash" */;
productName = Splash;
};
/* End XCSwiftPackageProductDependency section */ /* End XCSwiftPackageProductDependency section */
}; };
rootObject = E22E8757289D84C300E51191 /* Project object */; rootObject = E22E8757289D84C300E51191 /* Project object */;

View File

@ -8,6 +8,15 @@
"revision" : "77c3d8953374a9cf5418ef0bd7108524999de85a", "revision" : "77c3d8953374a9cf5418ef0bd7108524999de85a",
"version" : "0.5.1" "version" : "0.5.1"
} }
},
{
"identity" : "splash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/JohnSundell/Splash",
"state" : {
"revision" : "7f4df436eb78fe64fe2c32c58006e9949fa28ad8",
"version" : "0.16.0"
}
} }
], ],
"version" : 2 "version" : 2

View File

@ -1,5 +1,6 @@
import Foundation import Foundation
import Ink import Ink
import Splash
struct PageContentGenerator { struct PageContentGenerator {
@ -7,6 +8,8 @@ struct PageContentGenerator {
private let files: FileProcessor private let files: FileProcessor
private let swift = SyntaxHighlighter(format: HTMLOutputFormat())
init(factory: TemplateFactory, files: FileProcessor) { init(factory: TemplateFactory, files: FileProcessor) {
self.factory = factory self.factory = factory
self.files = files self.files = files
@ -31,8 +34,8 @@ struct PageContentGenerator {
} }
let codeModifier = Modifier(target: .codeBlocks) { html, markdown in let codeModifier = Modifier(target: .codeBlocks) { html, markdown in
if markdown.starts(with: "```swift") { if markdown.starts(with: "```swift") {
#warning("Syntax highlight swift code") let code = markdown.between("```swift", and: "```").trimmed
return html return "<pre><code>" + swift.highlight(code) + "</pre></code>"
} }
hasCodeContent = true hasCodeContent = true
return html return html