Updated example render_cell plugin in docs

This commit is contained in:
Simon Willison 2018-08-04 17:06:50 -07:00
commit 8dd255adae
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52

View file

@ -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"]