Skip to content

feat(text-format): shared chat text-format parser - #1726

Open
bmc08gt wants to merge 1 commit into
code/cashfrom
feat/text-format-parser
Open

bmc08gt wants to merge 1 commit into
code/cashfrom
feat/text-format-parser

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Adds :libs:text-format, a pure-Kotlin KMP module with one entry point, parseTextFormat(text, ranges). It turns chat markup (*bold*, _italic_, ~strike~, `code`, code blocks, > quotes, - /1. lists, [text](url) masked links) into the display text, styled spans and moved link/mention ranges. Rules are in the chat text-formatting spec, code-payments/flipcash-client-orchestrator#39. The parser exists once so Android and iOS cannot disagree character for character; iOS gets it through the SharedCore XCFramework.

  • ProtectedRange input, FormattedText output; offsets are UTF-16 code units. Link and mention detection stay in :apps:flipcash:shared:chat; the parser never detects either.
  • Word-character classes come from TextFormatUnicode.kt and its test, generated by test-vectors/gen_text_format_unicode.py (Unicode 16.0.0) from the orchestrator repo. Both files are committed as generated.
  • text_format.json (122 vectors) is copied byte for byte into src/commonTest/resources. One commonTest asserts every vector's display, spans and displayRanges, and a second test pins the file's sha256 so a stale copy fails.
  • :libs:text-format is registered in settings.gradle.kts, added to the kmpUnitTestModules list, and exported and api'd from :kmp:shared-core. shared-core-tests.yml now runs its iosSimulatorArm64Test and watches libs/text-format/**.

./gradlew :libs:text-format:allTests passes on testAndroidHostTest, iosSimulatorArm64Test and macosArm64Test. :kmp:shared-core:assembleSharedCoreReleaseXCFramework builds. Changing one display value in the copied fixture fails both vector tests.

Nothing consumes the module yet. ChatViewModel, buildMentionedText, the mention-pattern change and the link-detector trailing-marker cases are separate PRs.

Add :libs:text-format, a pure-Kotlin KMP module that parses chat markup
(bold, italic, strike, code, code blocks, quotes, lists, masked links)
into display text, styled spans and display ranges. Word-character
classes come from a generated Unicode 16.0.0 table so the JVM and iOS
classify identically. The module is exported from :kmp:shared-core.

The parser reads the 122 vectors of text_format.json from one commonTest,
which runs on the JVM and the iOS simulator target.
@bmc08gt
bmc08gt requested a review from jeffyanta as a code owner October 8, 2026 13:52
@bmc08gt bmc08gt self-assigned this Oct 8, 2026
@github-actions github-actions Bot added type: feature New functionality area: build-system Gradle, convention plugins, build-logic labels Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build-system Gradle, convention plugins, build-logic type: feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant