Releases: RandomHashTags/swift-htmlkit
0.11.0
Bug fix update by @RandomHashTags
Fixes
- non-global attribute values not being HTML escaped (commit)
- triple backslash quotation marks not being HTML escaped properly (commit)
- missing attribute value when rendering if the key was wrapped in the "`" character (affected attributes: as, for, default, defer)
- using interpolation in a multi-line context not being compiled correctly (commit, commit)
- html expansion with encodings other than
string
produce the wrong result (it didn't account for how the string delimiter should be represented) (#3) - certain syntax combinations missing their expected content when being expanded into interpolation, and causing SourceKit and swift-frontend to get stuck in infinite loops (#5, #6)
escapeHTML
macro not accounting for otherHTMLEncoding
s (commit)
Breaking changes
- changed the
htmlValue
computed property tofunc htmlValue(encoding:)
forHTMLInitializable
(commit)
Additions
- Literal expansion logic for the html macro is now publicly available through
HTMLKitUtilities.expandHTMLMacro
(commit) encoding
parameter to the#escapeHTML
macro. Default isstring
and, if contained in a#html
macro, the parent encoding (commit)CONTRIBUTING.md
.swift-format.json
Thanks
A special thanks to @andrebraga for reporting bugs that were fixed in this release!
Full Changelog: 0.10.0...0.11.0
0.10.0
Breaking changes
Content update by @RandomHashTags
Single Macro
This update replaces all html element macros with a single macro. Usage of the html element macros now drop the macro delimiter, compiled via the new #html
macro, and should remain at the end of the parameter list to behave identically as before.
The main reason behind this change is due to very poor code completion and compilation performance in projects that use this project extensively, which even I personally experienced. Plus it no longer pollutes the global namespace with over 100 related macros.
Other Changes
- The
#escapeHTML
macro remains unchanged, but the macros for different types have been replaced by the newHTMLEncoding
parameter in the new html macro. - All attribute values can now accept
nil
values. Attributes withnil
values are completely ignored when compiled/rendered. - The
var
element was renamed tovariable
- updated README to reflect all these changes (and updated benchmark pngs)
Removals
- Removed
swift-nio
dependency. You will need toimport NIOCore
if you want to useByteBuffer
as the HTMLEncoding.
New Syntax Examples
Examples of the new syntax
// <div class="dark"><p>Macros are beautiful</p></div>
#html(
div(attributes: [.class(["dark"])],
p("Macros are beautiful")
)
)
// <a href="https://github.com/RandomHashTags/litleagues" target="_blank"></a>
#html(
a(href: "https://github.com/RandomHashTags/litleagues", target: ._blank)
)
// <input id="funny-number" max="420" min="69" name="funny_number" step="1" type="number" value="69">
#html(
input(
attributes: [.id("funny-number")],
max: 420,
min: 69,
name: "funny_number",
step: 1,
type: .number,
value: "69"
)
)
Examples of the new HTMLEncoding
#html(
encoding: .string,
div()
)
#html(
encoding: .utf8Array,
div()
)
#html(
encoding: .utf16Array,
div()
)
#html(
encoding: .foundationData,
div()
)
#html(
encoding: .byteBuffer,
div()
)
Closing Notes
View the README to learn how to use the new syntax in a more in-depth manner. This update also allows developers to directly call the parsing code via HTMLKitUtilities.parseArguments
(and the escape html logic), which allows custom macros to incorporate the HTML expansions, which is especially useful if you want to fully implement a compile time solution for your custom static content (I know I do!).
Also contains a few bug fixes to corner cases and explicit usability.
Full Changelog: 0.9.0...0.10.0
I expect only additions and more fixes to corner cases for the 1.0.0 release. It is pretty much feature complete now, and I will be battle testing it more in the coming weeks.
0.9.0
This update brings a lot of fixes and adds missing attributes for certain elements. Plus HTMX support! (content update by @RandomHashTags )
Additions
- HTMX support via global attributes (view README on how to use)
- experimental
lookupFiles
attribute for html macros - added missing
shape
attribute toarea
- added missing
command
&commandfor
attributes tobutton
- added 5 missing attributes to
form
(action, enctype, method, novalidate, target) - added 9 missing attributes to
object
(archive, border, classid, codebase, codetype, data, declare, standby, usemap) - added missing
required
attribute totextarea
- added
ariaattribute
global attribute
Fixes
download
attribute behavior fora
controlslist
attribute behavior foraudio
allow
attribute behavior foriframe
rel
attribute behavior fora
,area
,form
, &link
httpEquiv
attribute behavior formeta
autocorrect
attribute behavior fortextarea
attributionSrc
attribute behavior fora
,img
, &script
(and renamed toattributionsrc
)
Changes
- empty string attribute value is now kept instead of being completely removed (don't assign the attribute if you don't want it)
- renamed
role
enum inHTMLElementAttribute.Extra
toariarole
and added more roles
Other
- organized imports
- README updates
Full Changelog: 0.8.0...0.9.0
This should be the last major update before the 1.0.0 release. Just want to make sure nothing hazardous still exists and the library is feature complete.
0.8.0
Changes
href
attribute can now contain an empty value (@RandomHashTags , commit)- replaced
runtimeValueNotAllowed
compiler error with automatic interpolation applied plusunsafeInterpolation
compiler warning (@RandomHashTags , commit)
Additions
trailingSlash
global attribute to support some xhtml; can only be applied to void elements (@RandomHashTags , commit)
Full Changelog: 0.7.1...0.8.0
1.0.0 release is just around the corner, and is expected to release before Nov 16.
0.7.1
Hotfix
- fixed a logic issue when flattening interpolation which resulted in other content contained in the same string that contains the interpolation to be missing; by @RandomHashTags (commit)
Full Changelog: 0.7.0...0.7.1
0.7.0
QOL update
This update adds more compile safety and errors/warnings where applicable when writing your html
Fixes
- Fixed an empty array still populating an attribute and value by @RandomHashTags (commit)
Improvements
- Better Elementary benchmark implementation by @sliemeobn (#1)
- Better interpolation flattening by @RandomHashTags (commit)
- Improved what node is being warned for
unsafeInterpolation
compiler warning by @RandomHashTags (commit) - Improved macro compilation performance by @RandomHashTags (commit, commit)
Additions
- Added macros for return types other than
String
by @RandomHashTags (commit) - Added
swift-nio
dependency to supportByteBuffer
html macro return type by @RandomHashTags (commit) - Added logos to badges in README by @RandomHashTags (commit)
- Added compiler error if runtime values are detected by @RandomHashTags (commit)
- Added SwiftDOM to Benchmarks by @RandomHashTags (commit)
Updates
- Updated Benchmark library Elementary to 0.4.1 by @RandomHashTags (commit)
- Use native Swim rendering in benchmarks by @RandomHashTags (commit)
- Updated
event
attribute deprecation message by @RandomHashTags (commit) - Updated
globalAttributeAlreadyDefined
compiler error message by @RandomHashTags (commit)
Removals
- Removed
StaticString
computed variablestring
in favor of Swift's nativeStaticString
's computed variabledescription
by @RandomHashTags (commit) - Removed unused
leaf
dependency in Benchmarks by @RandomHashTags (commit)
Other
- Added funding info by @RandomHashTags (commit)
- various updates to README (including benchmark pngs) to reflect these changes
New Contributors
- @sliemeobn made their first contribution in #1
Full Changelog: 0.6.0...0.7.0
0.6.0
Breaking changes
- dropped requirement of declaring innerHTML values in an array
// previous version (no longer compilable in 0.6.0)
#div(attributes: [.class(["dark"])], [
#p(["Macros are beautiful"])
])
// new version
#div(attributes: [.class(["dark"])],
#p("Macros are beautiful")
)
New
- can now escape HTML via
#escapeHTML()
macro or 4String
extension functions (HTML macros automatically escape characters) - writing string interpolation in HTML macros now throws a compiler warning saying it can introduce raw HTML
- dynamic benchmarks
Other
- fixed a case where creating a
StaticString
would not be permitted, even though it should've been - updated
swift-syntax
dependency url (wasapple/swift-syntax
, nowswiftlang/swift-syntax
) - more libraries benchmarked
- updates to README, including
- toned-down verbiage
- benchmarks are now pngs
- how to escape HTML
Full Changelog: 0.5.0...0.6.0
0.5.0
- fixed
attributionsrc
attribute (nowattributionSrc
) - fixed
html
element not allowing attributes - can now create custom elements and attributes (view README on how-to)
- added compile safety when declaring values for an attribute that takes an array (now disallows the separator character depending on the element)
- added benchmarks
- updates to README
- more unit tests
Full Changelog: 0.4.0...0.5.0
0.4.0
QOL improvements including:
- allowing the macros to return as any
ExpressibleByStringLiteral
(likeStaticString
)- NOTE: enforce all inner html declarations to conform to a specific
ExpressibleByStringLiteral
by assigning the type annotation
- NOTE: enforce all inner html declarations to conform to a specific
- fixed: allowing more than 1 of the same global attribute in the compiled result (now throws a compiler error)
- dropped inner label requirements for the
data
andevent
global attributes
Full Changelog: 0.3.0...0.4.0
0.3.0
Global attribute syntax changed (moved to attributes
label); extra attribute enums moved; added support for events.
Mainly to avoid bloating macro declarations with a billion options, which wastes space.
Full Changelog: 0.2.1...0.3.0