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

Enhance SVG Accessibility with 'title' and 'desc' in Groups #15

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Sources/SwiftSVG/Ellipse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public struct Ellipse: Element {

// MARK: - CustomStringConvertible
public var description: String {
let desc = "<ellipse cx=\"\(x)\" cy=\"\(y)\" rx=\"\(rx)\", ry=\"\(ry)\""
let desc = "<ellipse cx=\"\(x)\" cy=\"\(y)\" rx=\"\(rx)\" ry=\"\(ry)\""
return desc + " \(attributeDescription) />"
}
}
Expand Down
20 changes: 18 additions & 2 deletions Sources/SwiftSVG/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public struct Group: Container, Element {

// CoreAttributes
public var id: String?

public var title: String?
public var desc: String?

// PresentationAttributes
public var fillColor: String?
public var fillOpacity: Double?
Expand All @@ -50,6 +52,8 @@ public struct Group: Container, Element {
case rectangles = "rect"
case texts = "text"
case id
case title
case desc
case fillColor = "fill"
case fillOpacity = "fill-opacity"
case fillRule = "fill-rule"
Expand All @@ -68,7 +72,19 @@ public struct Group: Container, Element {

// MARK: - CustomStringConvertible
public var description: String {
return "<g \(attributeDescription) >\(containerDescription)\n</g>"
var contents: String = ""

if let title = self.title {
contents.append("\n<title>\(title)</title>")
}

if let desc = self.desc {
contents.append("\n<desc>\(desc)</desc>")
}

contents.append(containerDescription)

return "<g \(attributeDescription) >\(contents)\n</g>"
}
}

Expand Down
Loading