Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume changes to ImageReference making the alt property optional #27

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/DocCHTMLExporter/HTML/ReferenceHTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ extension DocCArchive.Reference {
return ref.abstract.generateHTML(in: ctx)

case .image(let ref):
return ref.alt.htmlEscaped
return ref.alt?.htmlEscaped ?? ""

case .link(let ref):
return ref.title.htmlEscaped

Expand Down Expand Up @@ -150,7 +150,7 @@ extension DocCArchive.ImageReference {
func generateHTML(in ctx: DZRenderingContext) -> String {
guard let variant = bestVariant(for: ctx.traits) else {
assertionFailure("Got no image variant?")
return "<!-- invalid image ref -->\(alt.htmlEscaped)"
return "<!-- invalid image ref -->\(alt?.htmlEscaped ?? "")"
}

let media : String = {
Expand All @@ -173,7 +173,7 @@ extension DocCArchive.ImageReference {
var ms = "<picture><source\(media) srcset='\(srcset)'>"

ms += "<img"
if !alt.isEmpty { ms += " alt='\(alt.htmlEscaped)'" }
if let alt = alt, !alt.isEmpty { ms += " alt='\(alt.htmlEscaped)'" }
ms += " srcset='\(srcset)'"
ms += " src='\(url.htmlEscaped)'"
if let size = variant.size { ms += " width='\(size.width)' height='auto'" }
Expand Down
Loading