Skip to content

v3.0.0

Choose a tag to compare

@danny1113 danny1113 released this 23 Feb 05:46
· 19 commits to main since this release

This is the next major release, with breaking changes that you may need to change your code.

Swift 6 Language Mode

Swift 6 language mode is now enabled for this package.

I have to remove the async version of parse(_:) for now because it violates the Swift 6 concurrency rules.

Rewrite the parse implementation

The parse implementation has been fully rewritten.

Perviously it relied on compiler internal detail to construct strongly typed tuple from [Any],
now it uses parameter pack to construct the result tuple.

Zero Dependency

HTMLParserBuilder now splits its tests to another package, remove SwiftSoup from the dependency.

Now you have to bring your own html parser and implement the Document and Element protocol,
you can check out the examples in Sources/HTMLParserBuilder/Example.

Rename

  • Capture → One
  • TryCapture → ZeroOrOne
  • CaptureAll → Many
  • Local → Group

Refactor

Previously, you can add a transform argument, it's now changed to map:

// v2.0
HTML {
    One("h1", transform: \.textContent)
    One("h2", transform: \.textContent)
} transform: { output -> Pair in
    Pair(output)
}

Group("#group") {
    One("h1", transform: \.textContent)
    One("h2", transform: \.textContent)
} transform: { output -> Pair in
    Pair(output)
}
// v3.0
HTML {
    One("h1", transform: \.textContent)
    One("h2", transform: \.textContent)
}
.map { output -> [Pair] in
    Pair(output)
}

Group("#group") {
    One("h1", transform: \.textContent)
    One("h2", transform: \.textContent)
}
.map { output -> [Pair] in
    Pair(output)
}

Protocol Requirements

  • rootElement: E → rootElement: E?
  • id: String → id: String?
  • tryQuerySelector(_ selector:) throws → query(selector:) throws
  • querySelectorAll(_:) → queryAll(selector:)
  • Remove querySelector(_:) -> Self?, use query(selector:) throws instead

Full Changelog: 2.0.0...v3.0.0