Swiftpack.co -  YOCKOW/SwiftXHTML as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
YOCKOW/SwiftXHTML
XHTML parser/generator in Swift.
.package(url: "https://github.com/YOCKOW/SwiftXHTML.git", from: "2.4.0")

What is SwiftXHTML?

SwiftXHTML will provide some functions related to XHTML.
It was originally written as a part of SwiftCGIResponder, and is intended to be used by it.

Requirements

  • Swift 5.1
  • macOS(>=10.15) or Linux

Dependencies

Dependencies

Usage

As a parser

import XHTML

let string = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Title</title>
  </head>
  <body>
    <div id="main">
      <h1>My Page</h1>
      <p>Welcome to my page.</p>
    </div>
  </body>
</html>
"""

let document = try Parser.parse(string.data(using: .utf8)!)

print(document.prolog.xmlVersion) // -> "1.0"
print(document.element(for: "main")!.name) // -> "div"

As a generator

import XHTML

let page = Document.template(title: "Title",
                             contents:[.text("It's my page.")])
print(page.xhtmlString)

/*
-- OUTPUT --
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Title</title></head><body>It&apos;s my page.</body></html>

*/

page.rootElement.body!.append(.comment("This is a comment."))
print(page.prettyXHTMLString)

/*
-- OUTPUT --
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>Title</title></head>
    <body>
        It&apos;s my page.
        <!--This is a comment.-->
    </body>
</html>

*/

What are not supported yet...

  • XPath
  • CSS selector
  • CSS parser

License

MIT License.
See "LICENSE.txt" for more information.

GitHub

link
Stars: 0
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Release v2.4.0
5 weeks ago

Introduce BlockLevelElement.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API