Skip to content

feat: label code blocks with their filename - #1210

Open
raz-iacob wants to merge 1 commit into
dev-null-sh:productionfrom
raz-iacob:feat/code-block-filenames
Open

raz-iacob wants to merge 1 commit into
dev-null-sh:productionfrom
raz-iacob:feat/code-block-filenames

Conversation

@raz-iacob

@raz-iacob raz-iacob commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A code block can now name its file after the language, and its header shows that filename instead of the language:

```php app/Models/User.php
```php title="app/Models/User.php"

The language still picks the highlighting, and fences with only a language look the same as before.

Changes

  • CodeSpans returns a filename with each code block, from whatever follows the language on the opening fence (title="…" is unwrapped). lib/code.ts mirrors it for drafts, with the same cases tested on both sides.
  • CodeBlock shows the filename in place of the language, truncated with the full path in title.
  • Block segments in the API gain a nullable filename key. Existing commits that already had text after the language (say {1,3}) now show that text as the label.

Validation

Local, on 01ed888f:

  • composer test:lint and composer test:types pass, type coverage is 100%.
  • composer test:unit: Pest 4,531 passed at 100% coverage. Node unit tests and Vitest pass apart from SeriesStash and 17 tests in ChatScroll/RemoteNotifications, which fail the same way on production and in its CI.
  • Layout shift is 0 on first load, client navigation from the log and a 35s polling cycle, at every viewport and theme below.

Visual evidence

Guest view of the same demo commit in Chrome (2x), production (e83d7c04) vs this branch.

Before After
1440×900 light
1440×900 dark
390×844 light
390×844 dark

1366×650: light before · light after · dark before · dark after

Device verification

No mobile interaction changes, only a label. 390×844 was checked with viewport emulation in Chrome, not on hardware or a simulator.

Independent review

A separate, read-only reviewer agent (given the task, the repo guidelines, the diff and these captures) returned CODE: PASS and VISUAL: PASS for e83d7c04..01ed888f, media ecc323c. Its one finding, client and server splitting the fence differently on non-space whitespace, was fixed and re-reviewed before that verdict.

Limitations

  • Not checked in Safari or Firefox.
  • The composer preview and Remotes use the same component but weren't captured; tests cover the client parser.

Summary by CodeRabbit

  • New Features
    • Fenced code blocks can include a filename after the language. When present, the filename appears in the block header, with the language shown when no filename is provided.
    • Quoted title attributes are also recognized as filenames.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7eda5ec9-2e5d-4e43-9741-d1bde178ed12
Commits

Reviewing files that changed from the base of the PR and between e83d7c0 and 01ed888.

Files selected for processing: 13
  • KNOWLEDGE_BASE.md
  • app/Services/CodeSpans.php
  • resources/js/components/code-block.tsx
  • resources/js/components/commit-body.tsx
  • resources/js/lib/code.ts
  • resources/js/types/commit.ts
  • tests/Feature/Controllers/CommitControllerTest.php
  • tests/Unit/ComposerPreview.test.tsx
  • tests/Unit/LinkifiedText.test.tsx
  • tests/Unit/NotificationInbox.test.tsx
  • tests/Unit/NotificationIndex.test.tsx
  • tests/Unit/QuotedCommit.test.tsx
  • tests/Unit/Services/CodeSpansTest.php

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Fenced code blocks now support filename metadata after the language. Server and client parsing add a nullable filename to block segments. The code block display shows the filename when present and otherwise shows the language.

Changes: Fenced Code Filenames

Layer / File(s) Summary
Parse and carry filename metadata
app/Services/CodeSpans.php, resources/js/lib/code.ts, resources/js/types/commit.ts, tests/Feature/Controllers/CommitControllerTest.php, tests/Unit/ComposerPreview.test.tsx, tests/Unit/Services/CodeSpansTest.php
The server and client parsers extract filename metadata from fenced code. Block segment results include a nullable filename field. Tests cover filename parsing, separators, and cases without a filename.
Display filename in code blocks
resources/js/components/code-block.tsx, resources/js/components/commit-body.tsx, tests/Unit/ComposerPreview.test.tsx, tests/Unit/LinkifiedText.test.tsx, tests/Unit/NotificationInbox.test.tsx, tests/Unit/NotificationIndex.test.tsx, tests/Unit/QuotedCommit.test.tsx, KNOWLEDGE_BASE.md
CommitBody passes the filename to CodeBlock. The header displays the filename when present and otherwise displays the language. Tests and the knowledge base describe or cover this behavior.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • dev-null-sh/dev-null.sh#857 — This change adds nullable filename metadata to block segments, which changes the response contract addressed by the OpenAPI documentation request.

Suggested reviewers: mnapoli, xheaven

Merge Risk: Minimal · up to 01ed8

Filename parsing and display have no identified merge-blocking issue; the change is ready for normal checks.

Security architecture risk: Minimal · up to 01ed8

The filename is a display label, not a file-access capability. It is rendered as escaped text and does not enter the highlighted HTML or clipboard paths. No material security risk was identified in the compared change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — An author can influence the label shown to readers of their code block. In the traced rendering path, this influence remains presentation metadata rather than a filesystem path, network destination or privileged operation.

Trust Boundaries and Controls

  • observed — Filename is rendered through React text and title bindings, not dangerouslySetInnerHTML. The existing clipboard action copies the code element’s textContent after a user action and does not incorporate the filename. These controls reject the candidate filename-to-markup or privileged-sink attack path.

Resilience and Maintainability Implications

  • observed — The new filename extraction constructs metadata from the current block input without introducing a persisted write, reservation or multi-step state transition. The added metadata therefore introduces no new cleanup, atomicity or recovery obligation in these parsing blocks.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat: label code blocks with their filename" matches the main change. The changeset adds an optional filename to code blocks across CodeSpans, lib/code.ts, the CodeBlock component, the Body…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat: label code blocks with their filename" matches the main change. The changeset adds an optional filename to code blocks across CodeSpans, lib/code.ts, the CodeBlock component, the BodySegment type, and the tests. The title names the primary behavior: code blocks now show their filename as a label. It is short and specific, and it uses the conventional commit prefix.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 12 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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.

1 participant