diff --git a/Sources/Generator/Generators/MarkdownProcessor.swift b/Sources/Generator/Generators/MarkdownProcessor.swift index e30fb03..cb05eeb 100644 --- a/Sources/Generator/Generators/MarkdownProcessor.swift +++ b/Sources/Generator/Generators/MarkdownProcessor.swift @@ -72,6 +72,7 @@ struct PageContentGenerator { private func processMarkdownImage(markdown: Substring, html: String, page: Element) -> String { // Split the markdown ![alt](file title) + // There are several known shorthand commands // For images: ![left_title](file right_title) // For videos: ![option1,option2,...](file) // For svg with custom area: ![x,y,width,height](file.svg) @@ -80,17 +81,8 @@ struct PageContentGenerator { // External pages: ![external](url1, text1; url2, text2, ...) let fileAndTitle = markdown.between("(", and: ")") let alt = markdown.between("[", and: "]").nonEmpty - switch alt { - case "download": - return handleDownloadButtons(page: page, content: fileAndTitle) - case "external": - return handleExternalButtons(page: page, content: fileAndTitle) - case "html": - return handleExternalHTML(page: page, file: fileAndTitle) - case "box": - return handleSimpleBox(page: page, content: fileAndTitle) - default: - break + if let alt = alt, let command = ShorthandMarkdownKey(rawValue: alt) { + return handleShortHandCommand(command, page: page, content: fileAndTitle) } let file = fileAndTitle.dropAfterFirst(" ") @@ -109,6 +101,19 @@ struct PageContentGenerator { return handleFile(page: page, file: file, fileExtension: fileExtension) } + private func handleShortHandCommand(_ command: ShorthandMarkdownKey, page: Element, content: String) -> String { + switch command { + case .downloadButtons: + return handleDownloadButtons(page: page, content: content) + case .externalLink: + return handleExternalButtons(page: page, content: content) + case .includedHtml: + return handleExternalHTML(page: page, file: content) + case .box: + return handleSimpleBox(page: page, content: content) + } + } + private func handleImage(page: Element, file: String, rightTitle: String?, leftTitle: String?) -> String { let imagePath = page.pathRelativeToRootForContainedInputFile(file) diff --git a/Sources/Generator/Generators/ShorthandMarkdownKey.swift b/Sources/Generator/Generators/ShorthandMarkdownKey.swift new file mode 100644 index 0000000..9a450c6 --- /dev/null +++ b/Sources/Generator/Generators/ShorthandMarkdownKey.swift @@ -0,0 +1,24 @@ +import Foundation + +enum ShorthandMarkdownKey: String { + + /** + A variable number of download buttons for file downloads + */ + case downloadButtons = "download" + + /** + A large button to an external page. + */ + case externalLink = "external" + + /** + Additional HTML code include verbatim into the page. + */ + case includedHtml = "html" + + /** + A box with a heading and a text description + */ + case box = "box" +}