Skip to content

Commit

Permalink
Enhance SVG Accessibility with 'title' and 'desc' in Groups (#15)
Browse files Browse the repository at this point in the history
* removed comma

* add optional title and desc tag for groups
  • Loading branch information
mac303 committed Jan 19, 2024
1 parent e18a6c9 commit b308ebd
Showing 1 changed file with 18 additions and 2 deletions.
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

0 comments on commit b308ebd

Please sign in to comment.