diff --git a/app/Devnull/Data/CommitBody.php b/app/Devnull/Data/CommitBody.php index 1cb98b1e..099f5251 100644 --- a/app/Devnull/Data/CommitBody.php +++ b/app/Devnull/Data/CommitBody.php @@ -184,6 +184,23 @@ public static function blocks(string $body, ?array $segments, array $mentions = return $blocks; } + /** + * Plain text as runs, with each standalone `/dev/null` outside code as a wordmark run, as the web's WordmarkText + * splits a guild's description or a Remote's preview (see partials/wordmark-text). + * + * @return list + */ + public static function wordmarkRuns(string $text): array + { + $runs = []; + + foreach (preg_split(self::CodeSpans, $text, flags: PREG_SPLIT_DELIM_CAPTURE) ?: [$text] as $index => $segment) { + array_push($runs, ...($index % 2 === 1 ? [new BodyRun($segment)] : self::withWordmarks($segment))); + } + + return $runs; + } + /** * Gives each hashtag that names a guild that guild, matched without case as devnull matches it, so it opens the * guild rather than a search, as the web's guild mentions do. diff --git a/resources/views/native/partials/body-run.blade.php b/resources/views/native/partials/body-run.blade.php index 2b7bdc34..bd6a511d 100644 --- a/resources/views/native/partials/body-run.blade.php +++ b/resources/views/native/partials/body-run.blade.php @@ -24,7 +24,7 @@ @elseif ($run->isHashtag && ! ($static ?? false)) @elseif ($run->isWordmark) -@if ($afterSpace)​@endif/⁠dev⁠null +@include('native.partials.wordmark', ['classes' => $pieceClasses.' '.$pieceInk, 'tight' => $pieceClasses === '']) @else @endif diff --git a/resources/views/native/partials/guild-header.blade.php b/resources/views/native/partials/guild-header.blade.php index 5e36c71f..5c255c63 100644 --- a/resources/views/native/partials/guild-header.blade.php +++ b/resources/views/native/partials/guild-header.blade.php @@ -42,7 +42,7 @@ @if ($guild->description !== '') - {{ $guild->description }} + @include('native.partials.wordmark-text', ['text' => $guild->description]) @endif {{ $guild->isPaused ? 'This guild is paused until it has a moderator. Its board and members are preserved.' : 'Include '.$guild->hashtag().' in any commit to post here.' }} diff --git a/resources/views/native/partials/guild-row.blade.php b/resources/views/native/partials/guild-row.blade.php index 6f02386d..cec85d47 100644 --- a/resources/views/native/partials/guild-row.blade.php +++ b/resources/views/native/partials/guild-row.blade.php @@ -13,7 +13,7 @@ {{ $guild->name }} {{ $guild->hashtag() }} @if ($guild->description !== '') - {{ $guild->description }} + @include('native.partials.wordmark-text', ['text' => $guild->description]) @endif {{ $members }} diff --git a/resources/views/native/partials/message-body.blade.php b/resources/views/native/partials/message-body.blade.php index 31e23f27..39cb2ecf 100644 --- a/resources/views/native/partials/message-body.blade.php +++ b/resources/views/native/partials/message-body.blade.php @@ -11,6 +11,7 @@ the guild's lane colour (see Guild::lane), which could match the colour of your own bubble. $maxLines caps the body to the first block at that many lines, for the pinned sheet's preview, so its links work before Show more. + A standalone /dev/null is the wordmark, in the bubble's ink (see partials/wordmark). --}} @php($linkInk ??= $mentionInk) @php($linkPrefixInk ??= 'text-theme-ink-muted') @@ -40,6 +41,8 @@ @elseif ($run->isHashtag) +@elseif ($run->isWordmark) +@include('native.partials.wordmark', ['afterSpace' => $loop->index > 0 && ctype_space(substr($block->runs[$loop->index - 1]->text, -1))]) @else @endif diff --git a/resources/views/native/partials/remote-row.blade.php b/resources/views/native/partials/remote-row.blade.php index 72320ca3..c13ef5f0 100644 --- a/resources/views/native/partials/remote-row.blade.php +++ b/resources/views/native/partials/remote-row.blade.php @@ -54,9 +54,9 @@ class="w-full" ]) @endif @if ($last?->isEvent()) - {{ $preview }} + @include('native.partials.wordmark-text', ['text' => $preview]) @else - {{ $preview }} + @include('native.partials.wordmark-text', ['text' => $preview]) @endif diff --git a/resources/views/native/partials/wordmark-text.blade.php b/resources/views/native/partials/wordmark-text.blade.php new file mode 100644 index 00000000..4f7bdaab --- /dev/null +++ b/resources/views/native/partials/wordmark-text.blade.php @@ -0,0 +1,18 @@ +{{-- + The inside of a text element for plain text, with each standalone /dev/null as the wordmark, where the web's + WordmarkText draws one: a guild's description and a Remote's preview (see CommitBody::wordmarkRuns and + partials/wordmark). Text without one is the text alone, as before. + + The runs sit flush with no line breaks between them, since a line break in text would print. +--}}@php($runs = \App\Devnull\Data\CommitBody::wordmarkRuns($text)) +@if (array_any($runs, fn ($run): bool => $run->isWordmark)) +@foreach ($runs as $run) +@if ($run->isWordmark) +@include('native.partials.wordmark', ['afterSpace' => $loop->index > 0 && ctype_space(substr($runs[$loop->index - 1]->text, -1))]) +@else + +@endif +@endforeach +@else +{{ $text }} +@endif diff --git a/resources/views/native/partials/wordmark.blade.php b/resources/views/native/partials/wordmark.blade.php new file mode 100644 index 00000000..3f3c3d23 --- /dev/null +++ b/resources/views/native/partials/wordmark.blade.php @@ -0,0 +1,8 @@ +{{-- + The /dev/null wordmark inside a run of text (see commit-body for how it's drawn and why). $afterSpace says it + follows a space, $classes are extra classes, and $tight false leaves out the tighter tracking, as a piece of a row + of words (see body-run). Nothing comes between this comment and the first directive, and the file ends without a + line break, since it sits inside whitespace-pre-wrap text. +--}}@php($afterSpace ??= false) +@php($tight ??= true) +@if ($afterSpace)​@endif/⁠dev⁠null \ No newline at end of file diff --git a/tests/Feature/Screens/ConversationTest.php b/tests/Feature/Screens/ConversationTest.php index c5d0eab9..d669e374 100644 --- a/tests/Feature/Screens/ConversationTest.php +++ b/tests/Feature/Screens/ConversationTest.php @@ -770,6 +770,20 @@ function pulledAvatars(TestableComponent $screen, int $id): array $screen->press("openGuild('android')")->assertNavigatedTo('/remotes/guilds/android'); }); +it('draws /dev/null in a message as the wordmark', function () { + serveRemoteThread(threadJson([ + remoteMessageJson(['id' => 1, 'body' => 'try the /dev/null app, not dev/null']), + ], ['read_through_id' => 1])); + + $screen = finishRefreshes(Native::visit('/remotes/conversations/ada')); + + expect(paragraphRuns($screen, 'try the'))->toBe([ + ['try the '], + ['/dev/null', 'wordmark'], + [' app, not dev/null'], + ]); +}); + it('opens no link preview that is not a web page', function () { serveRemoteThread(threadJson([ remoteMessageJson(['id' => 1, 'body' => 'Tap me', 'link_preview' => ['url' => 'javascript:alert(1)', 'title' => 'Tap me']]), diff --git a/tests/Feature/Screens/GuildTest.php b/tests/Feature/Screens/GuildTest.php index 0b83b051..a3ea0b0b 100644 --- a/tests/Feature/Screens/GuildTest.php +++ b/tests/Feature/Screens/GuildTest.php @@ -76,6 +76,12 @@ function guildMeta(TestableComponent $screen): string expect(guildMeta($paused))->toBe('#rust · Public guild · Paused · 1 member'); }); +it('draws /dev/null in the description as the wordmark, as the web does', function () { + serveBoard(['' => boardOf(['c1'], overrides: ['guild' => guildJson(['description' => 'Rust talk on /dev/null.'])])]); + + expect(paragraphRuns(finishRefreshes(Native::visit('/log/guilds/rust')), 'Rust talk'))->toBe([['Rust talk on '], ['/dev/null', 'wordmark'], ['.']]); +}); + it('opens a guilds directory link on top of the board, with a way back', function () { serveBoard(['' => boardOf(['c1'], overrides: ['data' => [commitJson(['id' => 'c1', 'body' => 'See https://dev-null.sh/guilds'])]])]); diff --git a/tests/Feature/Screens/GuildsTest.php b/tests/Feature/Screens/GuildsTest.php index f6d3f6c8..056ab4b8 100644 --- a/tests/Feature/Screens/GuildsTest.php +++ b/tests/Feature/Screens/GuildsTest.php @@ -79,6 +79,12 @@ function serveGuilds(array $pages): void ->and(nodeByRef($screen, 'guild-search-field')['props']['placeholder'])->toBe('Search guilds'); })->with(['ios', 'android']); +it("draws /dev/null in a guild's description as the wordmark", function () { + serveGuilds(['' => guildsPage([guildJson(['handle' => 'go', 'name' => 'Go', 'description' => 'Gophers on /dev/null'])])]); + + expect(paragraphRuns(finishRefreshes(Native::visit('/profile/guilds')), 'Gophers'))->toBe([['Gophers on '], ['/dev/null', 'wordmark']]); +}); + it('opens a tapped guild in the tab it was tapped in', function () { serveGuilds(['' => guildsPage([guildJson(['handle' => 'rust'])])]); diff --git a/tests/Feature/Screens/RemotesTest.php b/tests/Feature/Screens/RemotesTest.php index 1e4ac98d..41ed791c 100644 --- a/tests/Feature/Screens/RemotesTest.php +++ b/tests/Feature/Screens/RemotesTest.php @@ -40,6 +40,12 @@ ->and(app(Account::class)->unreadRemotes())->toBe(2); }); +it('draws /dev/null in the latest message as the wordmark, as the web inbox does', function () { + fakeApi(['GET /api/v1/remotes' => [remotesInboxJson([conversationJson(['last_message' => remoteMessageJson(['id' => 7, 'body' => 'try /dev/null'])])])]]); + + expect(paragraphRuns(finishRefreshes(Native::visit('/remotes')), 'try'))->toBe([['try '], ['/dev/null', 'wordmark']]); +}); + it('lists an org by its name, with how many are in it', function () { fakeApi(['GET /api/v1/remotes' => [remotesInboxJson([conversationJson([ 'id' => 'org-1', diff --git a/tests/Unit/Devnull/CommitBodyTest.php b/tests/Unit/Devnull/CommitBodyTest.php index 7872bbb3..ae889cdb 100644 --- a/tests/Unit/Devnull/CommitBodyTest.php +++ b/tests/Unit/Devnull/CommitBodyTest.php @@ -503,3 +503,13 @@ function quotesOf(array $blocks): array it('quotes a line that is only the marker', function () { expect(quotesOf(CommitBody::blocks('>', null)))->toBe([['quote', '']]); }); + +it('splits plain text around each standalone /dev/null and leaves code as written, as the web does', function (string $text, array $runs) { + expect(array_map(fn (BodyRun $run): array => [$run->text, $run->isWordmark], CommitBody::wordmarkRuns($text)))->toBe($runs); +})->with([ + ['Welcome to /dev/null.', [['Welcome to ', false], ['/dev/null', true], ['.', false]]], + ['/dev/null and /dev/null', [['/dev/null', true], [' and ', false], ['/dev/null', true]]], + ['run `cat /dev/null` on /dev/null', [['run ', false], ['`cat /dev/null`', false], [' on ', false], ['/dev/null', true]]], + ['dev/null, /dev/nullish and ./dev/null', [['dev/null, /dev/nullish and ./dev/null', false]]], + ['', []], +]);