Skip to content

Truncate displayed link text for the url column type#2840

Open
cycsmail wants to merge 1 commit into
simonw:mainfrom
cycsmail:truncate-url-column-type-1805
Open

Truncate displayed link text for the url column type#2840
cycsmail wants to merge 1 commit into
simonw:mainfrom
cycsmail:truncate-url-column-type-1805

Conversation

@cycsmail

Copy link
Copy Markdown
Contributor

Refs #1805

The auto-detected URL path already truncates link text according to truncate_cells_html, but the newer url custom column type rendered the full, untruncated URL as the visible link text. This makes UrlColumnType.render_cell() truncate the displayed text the same way, while keeping the full URL in the href.

Added a regression test in tests/test_column_types.py that sets truncate_cells_html=30, assigns the url column 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 plus tests/test_table_html.py pass locally, and black and ruff are clean.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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