Skip to content

Commit fb5821e

Browse files
committed
feat: wire --full and --css to convert --to html for SRT
- convert --to html file.srt now supports --full and --css dark|light - Use validatedInputURL in convert command (was inline English error) - Unify CSSStyle enum to cover all formats (minimal/web/dark/light)
1 parent ad8fd26 commit fb5821e

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

Sources/MacDocCLI/CLIHelpers.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ func buildAPAFullHTML(entries: [BibEntry], css: CSSStyle) -> String {
7474

7575
// MARK: - CSS Style Enum
7676

77+
/// Unified CSS style for all HTML-outputting converters.
78+
/// - bib: `minimal` (academic) or `web` (modern)
79+
/// - srt: `dark` (dark theme) or `light` (print-friendly)
7780
enum CSSStyle: String, ExpressibleByArgument, CaseIterable {
7881
case minimal
7982
case web
83+
case dark
84+
case light
8085
}

Sources/MacDocCLI/MacDoc+Convert.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension MacDoc {
2626
@Flag(name: .long, help: "Force output to stdout")
2727
var stdout: Bool = false
2828

29-
@Option(name: .long, help: "CSS style for bib→html: minimal (academic) or web (modern)")
29+
@Option(name: .long, help: "CSS style: minimal|web (bib), dark|light (srt)")
3030
var css: CSSStyle = .web
3131

3232
@Flag(name: .long, help: "Treat soft breaks as hard line breaks")
@@ -39,10 +39,7 @@ extension MacDoc {
3939
var input: String
4040

4141
mutating func run() throws {
42-
let inputURL = URL(fileURLWithPath: input)
43-
guard FileManager.default.fileExists(atPath: inputURL.path) else {
44-
throw ValidationError("File not found: \(input)")
45-
}
42+
let inputURL = try validatedInputURL(input)
4643

4744
let ext = inputURL.pathExtension.lowercased()
4845
let target = to.lowercased()
@@ -135,14 +132,20 @@ extension MacDoc {
135132
// MARK: - SRT → HTML
136133

137134
private func convertSRTToHTML(inputURL: URL) throws {
138-
let options = ConversionOptions.default
139135
let converter = SRTConverter()
140136

141-
if let outputPath = resolveOutputPath() {
142-
let outputURL = URL(fileURLWithPath: outputPath)
143-
try converter.convertToFile(input: inputURL, output: outputURL, options: options)
137+
if full {
138+
let cssString = css == .light ? SRTCSS.light : SRTCSS.dark
139+
let html = try converter.convertFull(input: inputURL, css: cssString)
140+
try writeStringOutput(html, to: resolveOutputPath())
144141
} else {
145-
try converter.convertToStdout(input: inputURL, options: options)
142+
let options = ConversionOptions.default
143+
if let outputPath = resolveOutputPath() {
144+
let outputURL = URL(fileURLWithPath: outputPath)
145+
try converter.convertToFile(input: inputURL, output: outputURL, options: options)
146+
} else {
147+
try converter.convertToStdout(input: inputURL, options: options)
148+
}
146149
}
147150
}
148151

0 commit comments

Comments
 (0)