Markup string interpolation#880
Merged
Merged
Conversation
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:
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 |
Use internal name for rendered markup contents
Collaborator
Author
|
@twostraws done; I've also taken the liberty of splitting up the |
MrSkwiggs
commented
May 11, 2026
Owner
|
I'm happy for this to be merged – really great work 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant improvements to the
Markupsystem, focusing on making HTML rendering safer, more expressive, and more efficient. The main changes include makingMarkupconform to Swift's string interpolation protocols, adding averbatiminitializer 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 newMarkupfeatures, and new tests are added to ensure correct publishing context behavior.Markup system improvements:
Markupis nowExpressibleByStringLiteralandExpressibleByStringInterpolation, allowing direct use of string interpolation for HTML generation and enabling publishing-time registrations to be handled during interpolation. [1] [2]verbatiminitializer toMarkupfor safely wrapping raw HTML strings, replacing previous direct string initializations throughout the codebase.+and.joined()operations forMarkupto use theverbatiminitializer for safe string combination. [1] [2]Element rendering updates:
Image,List,PlainDocument,Table,Text, andVideoto construct their HTML output using the newMarkupstring interpolation andverbatiminitializer, 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:
CoreAttributes.descriptionproperty no longer triggers publishing-time registrations, making it a pure description and preventing side effects when rendering attributes. TheregisterPublishingRequirementsmethod is removed. [1] [2]Testing and validation:
CoreAttributes.descriptionis pure inside a publishing context and thatMarkupstring interpolation correctly registers publishing-time requirements.