Skip to content

Tifroz/attributed text - #597

Merged
tifroz merged 3 commits into
skiptools:mainfrom
tifroz:tifroz/attributed-text
Nov 5, 2026
Merged

tifroz merged 3 commits into
skiptools:mainfrom
tifroz:tifroz/attributed-text

Conversation

@tifroz

@tifroz tifroz commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Thank you for contributing to the Skip project! Please review the contribution guide at https://skip.dev/docs/contributing/ for advice and guidance on making high-quality PRs.

Use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.

Skip Pull Request Checklist:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device
  • REQUIRED: I have checked whether this change requires a corresponding update in the Skip Fuse UI repository (link related PR if applicable)
  • OPTIONAL: I have added an example of any UI changes to the Showcase sample app

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

Codex generated the code, manually tested in the Showcase app

THIS PR DEPENDS ON skiptools/skip-foundation#143

Summary

Skip Lite callers can now style an AttributedString range and render those edits with Text(value), including ranges found with case-insensitive search. Previously, the transpiled initializer consumed the stored Markdown representation instead of the current editable attribute runs.

Render editable attributes in Skip Lite

Add typed font, foregroundColor, underlineStyle, strikethroughStyle, and baselineOffset properties to attributed strings, substrings, and attribute containers, with read access on runs. Convert the current Foundation runs into the existing attributed-text renderer, preserving links and inline presentation intents.

Source files:

  • Sources/SkipUI/SkipUI/Text/AttributedString.swift — added typed UI attributes.
  • Sources/SkipUI/SkipUI/Text/AttributedText.swift — converts editable Foundation runs.
  • Sources/SkipUI/SkipUI/Text/Text.swift — routes transpiled Text(AttributedString) through those runs.
  • Package.swift — requires the merged Foundation implementation.
  • README.md — documents usage and supported attributes.

Tests:

  • Created Tests/SkipUITests/EditableAttributedTextTests.swift: testRangeStylingAndCopyIndependence, testAttributeContainerAndRunAccess, and testCaseInsensitiveSearchHighlighting check typed attributes, copy independence, and highlighting a search result.
  • Created Tests/SkipUITests/Skip/EditableAttributedTextRenderingTests.kt: editedSwiftRangesReachMaterialText checks the actual Compose text, span boundaries, font, color, underline, baseline shift, and URL after a case-insensitive Unicode range edit.

Share inline Markdown conversion with Foundation

Use Foundation's editable attributed-string parser for markdownRuns(_:) and remove the duplicate inline Markdown helper. Attribute edits made after parsing are reflected in the rendered runs.

Source files:

  • Sources/SkipUI/SkipUI/Text/AttributedText.swift — uses Foundation's parsed runs.
  • Sources/SkipUI/Skip/InlineMarkdown.kt — removed.

Tests:

  • Created testEditedMarkdownProducesCurrentRenderRuns in Tests/SkipUITests/EditableAttributedTextTests.swift to check edited color, baseline offset, URL, and preserved inline styles.
  • Updated testInlineParsingPreservesWhitespaceWithinEmphasis in Tests/SkipUITests/AttributedTextTests.swift to accept coalesced runs while checking the full styled text.
  • Existing coverage in that file checks nested links, combined styles, whitespace, Unicode, escaping, entities, percent signs, literal HTML, null characters, and line endings.

Usage Example

var text = AttributedString("Search highlighting in Skip")
if let range = text.range(of: "skip", options: .caseInsensitive) {
    text[range].foregroundColor = .accentColor
    text[range].font = .headline
}
Text(text)

API Shape

New typed properties on AttributedString, AttributedSubstring, and AttributeContainer; read-only equivalents on AttributedString.Run:

var font: Font? { get set }
var foregroundColor: Color? { get set }
var underlineStyle: Text.LineStyle? { get set }
var strikethroughStyle: Text.LineStyle? { get set }
var baselineOffset: CGFloat? { get set }

The existing Text.init(_: AttributedString) signature is unchanged. Range searching and editing come from SkipFoundation.

Testing

Validated after rebasing, at 92f3777, with no editable dependencies:

  • swift test --build-system native --filter EditableAttributedTextTests: 3 Apple tests passed.
  • Gradle :SkipUI:testDebugUnitTest, filtered to AttributedTextTests, EditableAttributedTextTests, and EditableAttributedTextRenderingTests, with -Pkotlin.incremental=false: 14 Android tests passed, zero failures, errors, or skips.
  • Verified SwiftPM resolved the canonical merged Foundation commit.
  • git diff --check passed; the branch introduces no local package paths or debug artifacts.

The full package suite was not run.

Risks / Limitations

  • Requires the editable attributed-string and ICU search APIs merged in SkipFoundation PR #143. No release tag contains that merge yet, so the manifest pins canonical commit ba10460923b9e495bbd54ad494b8b0cb3dd7ba26. Replace this pin with the minimum containing release once available.
  • This supports Foundation's implemented subset: inferred ranges, typed UI properties, and editable inline Markdown. Generic attribute scopes and explicit Range<AttributedString.Index> slicing are not supported.
  • Underline and strikethrough rendering supports a single solid line.
  • Foundation search accepts [] and .caseInsensitive; ICU matching can differ from Apple Foundation, including the documented Straße/STRASSE difference.

@cla-bot cla-bot Bot added the cla-signed label Nov 4, 2026
@tifroz
tifroz merged commit 55c7b41 into skiptools:main Nov 5, 2026
3 checks passed
tifroz added a commit to skiptools/skipapp-showcase that referenced this pull request Nov 5, 2026
…les + superscript)

Depends on 3 merged PRs - the dependencies are pinned to their respective commit until the next release

- [SkipFoundation #143](skiptools/skip-foundation#143)
- [SkipUI #597](skiptools/skip-ui#597)
- [SkipFuseUI #164](skiptools/skip-fuse-ui#164). 

* Added attributed text examples using merged Skip dependencies
* Added shared attributed-text and search highlighting examples
* Listed editable attributed text in the playground index
* Avoided Swift type-check timeout in the Alert playground
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant