Skip to content

Releases: RandomHashTags/swift-htmlkit

0.11.0

05 Dec 15:33
Compare
Choose a tag to compare

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 other HTMLEncodings (commit)

Breaking changes

  • changed the htmlValue computed property to func htmlValue(encoding:) for HTMLInitializable (commit)

Additions

  • Literal expansion logic for the html macro is now publicly available through HTMLKitUtilities.expandHTMLMacro (commit)
  • encoding parameter to the #escapeHTML macro. Default is string 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

24 Nov 15:17
Compare
Choose a tag to compare

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 new HTMLEncoding parameter in the new html macro.
  • All attribute values can now accept nil values. Attributes with nil values are completely ignored when compiled/rendered.
  • The var element was renamed to variable
  • updated README to reflect all these changes (and updated benchmark pngs)

Removals

  • Removed swift-nio dependency. You will need to import NIOCore if you want to use ByteBuffer 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

15 Nov 05:59
Compare
Choose a tag to compare

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 to area
  • added missing command & commandfor attributes to button
  • 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 to textarea
  • added ariaattribute global attribute

Fixes

  • download attribute behavior for a
  • controlslist attribute behavior for audio
  • allow attribute behavior for iframe
  • rel attribute behavior for a, area, form, & link
  • httpEquiv attribute behavior for meta
  • autocorrect attribute behavior for textarea
  • attributionSrc attribute behavior for a, img, & script (and renamed to attributionsrc)

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 in HTMLElementAttribute.Extra to ariarole 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

01 Nov 12:33
Compare
Choose a tag to compare

Changes

  • href attribute can now contain an empty value (@RandomHashTags , commit)
  • replaced runtimeValueNotAllowed compiler error with automatic interpolation applied plus unsafeInterpolation 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

23 Oct 12:17
Compare
Choose a tag to compare

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

23 Oct 10:45
Compare
Choose a tag to compare

QOL update

This update adds more compile safety and errors/warnings where applicable when writing your html

Fixes

Improvements

Additions

Updates

Removals

  • Removed StaticString computed variable string in favor of Swift's native StaticString's computed variable description 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

Full Changelog: 0.6.0...0.7.0

0.6.0

12 Oct 10:33
Compare
Choose a tag to compare

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 4 String 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 (was apple/swift-syntax, now swiftlang/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

06 Oct 07:53
Compare
Choose a tag to compare
  • fixed attributionsrc attribute (now attributionSrc)
  • 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

22 Sep 22:25
Compare
Choose a tag to compare

QOL improvements including:

  • allowing the macros to return as any ExpressibleByStringLiteral (like StaticString)
    • NOTE: enforce all inner html declarations to conform to a specific ExpressibleByStringLiteral by assigning the type annotation
  • 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 and event global attributes

Full Changelog: 0.3.0...0.4.0

0.3.0

22 Sep 04:43
Compare
Choose a tag to compare

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