Skip to content

Commit c0b862e

Browse files
authored
Merge pull request #1162 from processing/1121-2.0
Fix broken p5.* reference links in reference pages [2.0]
2 parents 328d625 + 0b7101f commit c0b862e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/layouts/ReferenceItemLayout.astro

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ const descriptionParts = description.split(
9090
/(<pre><code class="language-js(?: example)?">[\s\S]+?<\/code><\/pre>)/gm
9191
);
9292
93+
// Normalizes malformed p5.* reference anchors (e.g. "#/p5.Element")
94+
// to proper reference routes ("/reference/p5/p5.Element/")
95+
function normalizeP5ReferenceLinks(html: string | undefined): string | undefined {
96+
if (!html) return html;
97+
return html.replace(
98+
/href="#\/(p5\.[^"]+)"/g,
99+
'href="/reference/p5/$1/"'
100+
);
101+
}
93102
---
94103

95104
<Head title={entry.data.title} locale={currentLocale} />
@@ -208,7 +217,7 @@ const descriptionParts = description.split(
208217
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
209218
>
210219
{param.type && <span>{param.type}: </span>}
211-
<span set:html={param.description} />
220+
<span set:html={normalizeP5ReferenceLinks(param.description)} />
212221
</div>
213222
</div>
214223
))}
@@ -226,7 +235,7 @@ const descriptionParts = description.split(
226235
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
227236
>
228237
{param.type && <span>{param.type}: </span>}
229-
<span set:html={param.description} />
238+
<span set:html={normalizeP5ReferenceLinks(param.description)} />
230239
</div>
231240
</div>
232241
)
@@ -246,7 +255,7 @@ const descriptionParts = description.split(
246255
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
247256
>
248257
{entry.data.return.type && <span>{entry.data.return.type}: </span>}
249-
<span set:html={entry.data.return.description} />
258+
<span set:html={normalizeP5ReferenceLinks(entry.data.return.description)} />
250259
</div>
251260
</div>
252261
</div>

0 commit comments

Comments
 (0)