mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Updated example render_cell plugin in docs
This commit is contained in:
parent
61e9a4d601
commit
8dd255adae
1 changed files with 4 additions and 0 deletions
|
|
@ -297,6 +297,8 @@ If the value matches that pattern, the plugin returns an HTML link element:
|
|||
@hookimpl
|
||||
def render_cell(value):
|
||||
# Render {"href": "...", "label": "..."} as link
|
||||
if not isinstance(value, str):
|
||||
return None
|
||||
stripped = value.strip()
|
||||
if not stripped.startswith("{") and stripped.endswith("}"):
|
||||
return None
|
||||
|
|
@ -304,6 +306,8 @@ If the value matches that pattern, the plugin returns an HTML link element:
|
|||
data = json.loads(value)
|
||||
except ValueError:
|
||||
return None
|
||||
if not isinstance(data, dict):
|
||||
return None
|
||||
if set(data.keys()) != {"href", "label"}:
|
||||
return None
|
||||
href = data["href"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue