Skip to content

Commit ffad986

Browse files
authored
fix: linkify URL field values in rendered markdown (#1335)
1 parent 621acef commit ffad986

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/lib/server/render/pub/renderMarkdownWithPub.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const visitValueDirective = (node: Directive, context: utils.RenderWithPubContex
4747
const field = expect(attrs.field, "Missing field attribute in value directive");
4848

4949
let value: unknown = attrs.fallback;
50+
let valueIsUrl = false;
5051

5152
const hydratedPubValues = hydratePubValues(context.pub.values);
5253

@@ -56,6 +57,9 @@ const visitValueDirective = (node: Directive, context: utils.RenderWithPubContex
5657
const val = hydratedPubValues.find((value) => value.fieldSlug === field);
5758

5859
if (val !== undefined) {
60+
if (val.schemaName === CoreSchemaType.URL) {
61+
valueIsUrl = true;
62+
}
5963
value =
6064
val.schemaName === CoreSchemaType.DateTime
6165
? // get the date in YYYY-MM-DD format
@@ -72,13 +76,17 @@ const visitValueDirective = (node: Directive, context: utils.RenderWithPubContex
7276

7377
node.data = {
7478
...node.data,
75-
hName: "span",
79+
hName: valueIsUrl ? "a" : "span",
7680
hChildren: [
7781
{
7882
type: "text",
7983
value: String(value),
8084
},
8185
],
86+
hProperties: {
87+
...node.data?.hProperties,
88+
...(valueIsUrl ? { href: String(value) } : {}),
89+
},
8290
};
8391
};
8492

0 commit comments

Comments
 (0)