Skip to content

Markup string interpolation#880

Merged
MrSkwiggs merged 8 commits into
mainfrom
markup-string-interpolation
May 11, 2026
Merged

Markup string interpolation#880
MrSkwiggs merged 8 commits into
mainfrom
markup-string-interpolation

Conversation

@MrSkwiggs
Copy link
Copy Markdown
Collaborator

This pull request introduces significant improvements to the Markup system, focusing on making HTML rendering safer, more expressive, and more efficient. The main changes include making Markup conform to Swift's string interpolation protocols, adding a verbatim initializer for raw HTML, and ensuring that publishing-time registrations are handled only during markup interpolation (not during attribute description). These changes streamline HTML generation, reduce boilerplate, and prevent unintended side effects. Several element renderers are updated to leverage the new Markup features, and new tests are added to ensure correct publishing context behavior.

Markup system improvements:

  • Markup is now ExpressibleByStringLiteral and ExpressibleByStringInterpolation, allowing direct use of string interpolation for HTML generation and enabling publishing-time registrations to be handled during interpolation. [1] [2]
  • Added a verbatim initializer to Markup for safely wrapping raw HTML strings, replacing previous direct string initializations throughout the codebase.
  • Updated + and .joined() operations for Markup to use the verbatim initializer for safe string combination. [1] [2]

Element rendering updates:

  • Updated elements like Image, List, PlainDocument, Table, Text, and Video to construct their HTML output using the new Markup string interpolation and verbatim initializer, resulting in cleaner and safer code. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

Core attributes and publishing context:

  • The CoreAttributes.description property no longer triggers publishing-time registrations, making it a pure description and preventing side effects when rendering attributes. The registerPublishingRequirements method is removed. [1] [2]

Testing and validation:

  • Added tests to ensure that CoreAttributes.description is pure inside a publishing context and that Markup string interpolation correctly registers publishing-time requirements.

@MrSkwiggs MrSkwiggs requested a review from twostraws May 11, 2026 09:58
@MrSkwiggs MrSkwiggs self-assigned this May 11, 2026
@twostraws
Copy link
Copy Markdown
Owner

This looks excellent – thank you! The only concern I have is that you've needed to manually correct places to use Markup, but contributors in the future might not spot that particular footgun. If we can find a way to lock that down so it becomes harder if not impossible, I would be happier.

Potentially that might mean:

  1. Remove CustomStringConvertible from CoreAttributes.
  2. Add an internal explicit renderer, e.g. var markupAttributeString: String - something that is really clear, rather than usable by accident.
  3. Have Markup.StringInterpolation.appendInterpolation(_ attributes: CoreAttributes) use that.
  4. Optionally add an unavailable String.StringInterpolation overload for CoreAttributes, so "\(attributes)" in plain strings becomes a compile-time error.

Hopefully that last part should (I think) firmly close the door on accidental mistakes from future contributors, e.g.:

extension String.StringInterpolation {
    @available(*, unavailable, message: "Interpolate CoreAttributes into Markup, not String.")
    mutating func appendInterpolation(_ attributes: CoreAttributes) {}
}

I think that ought to work.

We might also be able to remove init(_ markup: Markup)?

@MrSkwiggs
Copy link
Copy Markdown
Collaborator Author

@twostraws done; I've also taken the liberty of splitting up the CoreAttributes.swift file (3e4d658)- but if it doesn't belong in here I can just revert that commit

Comment thread Sources/Ignite/Framework/Typealii.swift Outdated
@twostraws
Copy link
Copy Markdown
Owner

I'm happy for this to be merged – really great work 👍

@MrSkwiggs MrSkwiggs merged commit 64fb3ff into main May 11, 2026
1 check passed
@MrSkwiggs MrSkwiggs deleted the markup-string-interpolation branch May 11, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants