|
32 | 32 | import Foundation |
33 | 33 |
|
34 | 34 | extension XMLParser { |
35 | | - |
36 | | - func parseText(_ att: AttributeParser, element: XML.Element) throws -> DOM.Text? { |
37 | | - guard |
38 | | - let text = element.innerText?.trimmingCharacters(in: .whitespacesAndNewlines), |
39 | | - !text.isEmpty else { |
40 | | - return nil |
| 35 | + |
| 36 | + func parseText(_ att: AttributeParser, element: XML.Element) throws -> DOM.Text? { |
| 37 | + guard |
| 38 | + let text = element.innerText?.trimmingCharacters(in: .whitespacesAndNewlines), |
| 39 | + !text.isEmpty else { |
| 40 | + return nil |
| 41 | + } |
| 42 | + |
| 43 | + return try parseText(att, value: text) |
| 44 | + } |
| 45 | + |
| 46 | + func parseAnchor(_ att: AttributeParser, element: XML.Element) throws -> DOM.Anchor? { |
| 47 | + let anchor = DOM.Anchor() |
| 48 | + anchor.href = try att.parseUrl("href") |
| 49 | + anchor.childElements = try parseContainerChildren(element) |
| 50 | + return anchor |
| 51 | + } |
| 52 | + |
| 53 | + func parseText(_ att: AttributeParser, value: String) throws -> DOM.Text { |
| 54 | + let element = DOM.Text(value: value) |
| 55 | + element.x = try att.parseCoordinate("x") |
| 56 | + element.y = try att.parseCoordinate("y") |
| 57 | + element.attributes.fontFamily = (try att.parseString("font-family"))?.trimmingCharacters(in: .whitespacesAndNewlines) |
| 58 | + element.attributes.fontSize = try att.parseFloat("font-size") |
| 59 | + return element |
41 | 60 | } |
42 | | - |
43 | | - return try parseText(att, value: text) |
44 | | - } |
45 | | - |
46 | | - func parseText(_ att: AttributeParser, value: String) throws -> DOM.Text { |
47 | | - let element = DOM.Text(value: value) |
48 | | - element.x = try att.parseCoordinate("x") |
49 | | - element.y = try att.parseCoordinate("y") |
50 | | - element.attributes.fontFamily = (try att.parseString("font-family"))?.trimmingCharacters(in: .whitespacesAndNewlines) |
51 | | - element.attributes.fontSize = try att.parseFloat("font-size") |
52 | | - return element |
53 | | - } |
54 | 61 | } |
0 commit comments