Truncate displayed link text for the url column type#2840
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1be0a6df78
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| url = value.strip() | ||
| escaped = markupsafe.escape(url) | ||
| truncated = markupsafe.escape( | ||
| truncate_url(url, datasette.setting("truncate_cells_html")) |
There was a problem hiding this comment.
Preserve full URL text on row pages
When a table column is assigned the built-in url column type and truncate_cells_html is nonzero, this now truncates the link text everywhere the column type renderer is used. Individual row HTML pages deliberately call display_columns_and_rows(..., truncate_cells=0) so users can see/copy the full value there, but this line bypasses that per-page setting by reading the global setting directly; long URL values on /db/table/pk pages will now be shortened even though the row-page behavior is supposed to show full cell contents.
Useful? React with 👍 / 👎.
Refs #1805
The auto-detected URL path already truncates link text according to
truncate_cells_html, but the newerurlcustom column type rendered the full, untruncated URL as the visible link text. This makesUrlColumnType.render_cell()truncate the displayed text the same way, while keeping the full URL in thehref.Added a regression test in
tests/test_column_types.pythat setstruncate_cells_html=30, assigns theurlcolumn type to a column holding an 87-char URL, and checks the link text is truncated (contains…) while the href stays intact. It fails without the source change. That test plustests/test_table_html.pypass locally, and black and ruff are clean.