Skip to content
/ Slab Public

Swift package to convert a HTML table into an array of dictionaries.

License

Notifications You must be signed in to change notification settings

ptrkstr/Slab

Repository files navigation





Swift package to convert a HTML table into an array of dictionaries.

Example

GIVEN I have the following table

A B
1 2
3 4

WHEN I use Slab

let array: [[String: String]] = try Slab().convert(htmlString)

THEN I see an array of dictionaries

[
    ["A": "1", "B": "2"],
    ["A": "3", "B": "4"]
]

Features

Colspan Support

A B
1
3 4
[
    ["A": "1", "B": "1"],
    ["A": "3", "B": "4"]
]

Rowspan Support

A B
1 2
4
[
    ["A": "1", "B": "2"],
    ["A": "4", "B": "2"]
]

Linebreak Support

A
A
B
1 2
3
3
4
[
    ["A\\nA": "1", "B": "2"],
    ["A\\nA": "3\\n3", "B": "2"]
]

Modification

Prior to row data being entered, you have the opportunity to modify the SwiftSoup.Element.

A[1] B
1 2[2]
Configuration(modify: { element, row, column in
    try element.select("sup").remove()
    return element
})
[
    ["A": "1", "B": "2"]
]

Notes

  • Empty <td></td> is converted into an empty String

Installation

SPM

Add the following to your project:

https://github.com/ptrkstr/Slab

About

Swift package to convert a HTML table into an array of dictionaries.

Topics

Resources

License

Stars

Watchers

Forks

Languages