Updates and fixes

This commit is contained in:
2025-10-25 00:04:37 -04:00
parent 743fc51873
commit 58a8419984
8 changed files with 174 additions and 13 deletions

97
CLA.txt Normal file
View File

@@ -0,0 +1,97 @@
You accept and agree to the following terms and conditions for Your
Contributions (present and future) that you submit to the Grantee. In
return, the Grantee shall not use Your Contributions in a way that
is contrary to the public benefit. Except for the license granted
herein to the Grantee and recipients of software distributed by the
Grantee, You reserve all right, title, and interest in and to Your
Contributions.
1. Definitions.
"The Grantee" shall mean Isaac Roy Paul (a.k.a izackp@gmail.com), a
individual with its principal place of business in Florida, USA.
"You" (or "Your") shall mean the copyright owner or legal entity
authorized by the copyright owner that is making this Agreement
with the Grantee. For legal entities, the entity making a
Contribution and all other entities that control, are controlled
by, or are under common control with that entity are considered to
be a single Contributor. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"Contribution" shall mean any original work of authorship,
including any modifications or additions to an existing work, that
is intentionally submitted by You to the Grantee for inclusion
in, or documentation of, any of the products owned or managed by
the Grantee (the "Work"). For the purposes of this definition,
"submitted" means any form of electronic, verbal, or written
communication sent to the Grantee or its representatives,
including but not limited to communication on electronic mailing
lists, source code control systems, and issue tracking systems that
are managed by, or on behalf of, the Grantee for the purpose of
discussing and improving the Work, but excluding communication that
is conspicuously marked or otherwise designated in writing by You
as "Not a Contribution."
2. Grant of Copyright License. Subject to the terms and conditions of
this Agreement, You hereby grant to the Grantee and to
recipients of software distributed by the Grantee a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare derivative works of,
publicly display, publicly perform, sublicense, and distribute Your
Contributions and such derivative works.
3. Grant of Patent License. Subject to the terms and conditions of
this Agreement, You hereby grant to the Grantee and to
recipients of software distributed by the Grantee a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the
Work, where such license applies only to those patent claims
licensable by You that are necessarily infringed by Your
Contribution(s) alone or by combination of Your Contribution(s)
with the Work to which such Contribution(s) was submitted. If any
entity institutes patent litigation against You or any other entity
(including a cross-claim or counterclaim in a lawsuit) alleging
that your Contribution, or the Work to which you have contributed,
constitutes direct or contributory patent infringement, then any
patent licenses granted to that entity under this Agreement for
that Contribution or Work shall terminate as of the date such
litigation is filed.
4. You represent that you are legally entitled to grant the above
license. If your employer(s) has rights to intellectual property
that you create that includes your Contributions, you represent
that you have received permission to make Contributions on behalf
of that employer, that your employer has waived such rights for
your Contributions to the Grantee, or that your employer has
executed a separate Corporate CLA with the Grantee.
5. You represent that each of Your Contributions is Your original
creation (see section 7 for submissions on behalf of others). You
represent that Your Contribution submissions include complete
details of any third-party license or other restriction (including,
but not limited to, related patents and trademarks) of which you
are personally aware and which are associated with any part of Your
Contributions.
6. You are not expected to provide support for Your Contributions,
except to the extent You desire to provide support. You may provide
support for free, for a fee, or not at all. Unless required by
applicable law or agreed to in writing, You provide Your
Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied, including, without
limitation, any warranties or conditions of TITLE, NON-
INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
7. Should You wish to submit work that is not Your original creation,
You may submit it to the Grantee separately from any
Contribution, identifying the complete details of its source and of
any license or other restriction (including, but not limited to,
related patents, trademarks, and license agreements) of which you
are personally aware, and conspicuously marking the work as
"Submitted on behalf of a third-party: [named here]".
8. You agree to notify the Grantee of any facts or circumstances of
which you become aware that would make these representations
inaccurate in any respect.

View File

@@ -33,7 +33,7 @@ URL for them above, as well as copies of any plain-text lines
beginning with `Required Notice:` that the licensor provided beginning with `Required Notice:` that the licensor provided
with the software. For example: with the software. For example:
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com) > Required Notice: Copyright Isaac Paul
## Changes and New Works License ## Changes and New Works License

14
Package.resolved Normal file
View File

@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "309a47b2b1d9b5e991f36961c983ecec72275be3",
"version" : "1.6.1"
}
}
],
"version" : 2
}

View File

@@ -1,4 +1,4 @@
// swift-tools-version:5.9 // swift-tools-version:6.1.0
// //
// Package.swift // Package.swift
@@ -16,19 +16,29 @@ let package = Package(
.library( .library(
name: "HRW", name: "HRW",
targets: ["HRW"] targets: ["HRW"]
) ),
], ],
dependencies: [ dependencies: [
.package(path: "/Users/isaacpaul/Projects/swift-projects/GenHTML5")
], ],
targets: [ targets: [
.target( .target(
name: "HRW", name: "HRW",
dependencies: [ dependencies: [ ]
]
), ),
.testTarget( .testTarget(
name: "HRWTests", name: "HRWTests",
dependencies: ["HRW"] dependencies: [
"HRW"],
sources: ["example.html"],
plugins: [.plugin(name: "BindingPlugin", package: "genhtml5")]
) )
] ]
) )
/*
Showing All Messages
product 'BindingGenerator' required by package 'hrw' target 'HRWTests' not found. Did you mean ''?
*/

View File

@@ -1,10 +1,10 @@
## HTML Reader Writer (H-RW) ## HTML Reader Writer (H-RW)
The goal is to be able to load html into swift from a file, manipulate it, then spit out html while retaining the benefits of a type safe language which serves as an alternative to templating. The goal is to be able to load html into swift from a file, manipulate it, then spit out html while retaining the benefits of a type safe language which serves as an alternative to templating. A BindingPlugin is also provided, this will analyze the html files and produce a swift file that will let you access html elements with IDs while retaining type infomation. Similar to Android's ViewBinding.
#### Thoughts #### Thoughts
I suppose I wanted to be able to use plain html as is. In hindsight, it was too much effort for the payoff. This is mostly so I can build multipage websites with swift without the use of JS as a silly experiement. I suppose I wanted to be able to use plain html as is. In hindsight, it was too much effort for the payoff. This is mostly so I can build multipage websites with swift without the use of JS as a silly experiment.
There is also a HTML library called Plot that also lets you manipulate html, but it doesn't let you load it in from a file and treats HTML generations similarly to SwiftUI. There is also a HTML library called Plot that also lets you manipulate html, but it doesn't let you load it in from a file and treats HTML generations similarly to SwiftUI.
@@ -12,11 +12,14 @@ Perhaps this project can be repurposed as an LSP for html, but that's not much o
There is also an HTML parser in LadyBird thats partially written in Swift. It seems to call into c++ for a handful of things, so it doesn't seem to be reusable without that. There is also an HTML parser in LadyBird thats partially written in Swift. It seems to call into c++ for a handful of things, so it doesn't seem to be reusable without that.
## License ## License
The license is a modified version of the PolyForm Noncommercial License (1.0.0) to add more non-commerical and non-ai use stipulations. I am open relicensing. The license is a modified version of the PolyForm Noncommercial License (1.0.0) to add more non-commercial and non-ai use stipulations. Basically, if you're not making money then it's free to use. Depending on the project, I am open to distributing this source under a different license.
## Contributions ## Contributions
All contributors must sign an CLA as I do not wish to restrict myself in the use of the code or future relicensing endevors. All contributors must agree to the CLA within. It is primarily based on Apache's ICLA.
By signing off your git commits you are agreeing the CLA within the repository inside the file CLA.txt.
You can sign off your commits via the signoff flag `git commit --signoff`

View File

@@ -147,6 +147,43 @@ public class HTMLNode : XMLNode, IGlobalContainer {
return nil return nil
} }
public func iterate(_ index:Int, _ skipTextNodes:Bool, _ cb:(HTMLNode, Int)->()) -> Int {
if (skipTextNodes && self is HTMLText) {
return index
}
cb(self, index)
var newIndex = index + 1
for eachChild in children {
newIndex = eachChild.iterate(newIndex, skipTextNodes, cb)
}
return newIndex
}
public func flatten() -> [HTMLNode] {
let count = countElements()
let result:[HTMLNode] = Array(unsafeUninitializedCapacity: count+1) { buffer, initializedCount in
initializedCount = self.addTo(array: &buffer, index: 0)
}
return result
}
public func countElements() -> Int {
var result = 1
for eachChild in children {
result += eachChild.countElements()
}
return result
}
private func addTo(array:inout UnsafeMutableBufferPointer<HTMLNode>, index:Int) -> Int {
array.initializeElement(at: index, to: self)
var newIndex = index + 1
for eachChild in children {
newIndex = eachChild.addTo(array: &array, index: newIndex)
}
return newIndex
}
public override func renderAttributes() -> String { public override func renderAttributes() -> String {
var result = super.renderAttributes() var result = super.renderAttributes()
var first = result.count == 0 var first = result.count == 0

View File

@@ -27,7 +27,7 @@ public class HTMLParser {
} }
*/ */
//TODO: Not really an html node.. //TODO: Not really an html node..
public class HTMLText : HTMLNode, IFlowContent { public class HTMLText : HTMLNode, IFlowContent, IPhrasing, IFlow {
public var content: String public var content: String

View File

@@ -385,7 +385,7 @@ public class XMLParser
return String(cString: buffer) return String(cString: buffer)
}*/ }*/
init?(str:String) { public init?(str:String) {
iterator = str.unicodeScalars.makeIterator() iterator = str.unicodeScalars.makeIterator()
position = Position() position = Position()
} }