Skip to content

Commit a16bf1e

Browse files
authored
Merge pull request #1121 from rakesh2OO5/fix/issue-1120
Fix broken p5.* reference links in reference pages
2 parents 8dc7b59 + 8d060aa commit a16bf1e

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 { showBanner, englishUrl } = checkTranslationBanner(
9090
Astro.url.pathname,
9191
Astro.url.origin
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} />
@@ -196,7 +205,7 @@ const { showBanner, englishUrl } = checkTranslationBanner(
196205
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
197206
>
198207
{param.type && <span>{param.type}: </span>}
199-
<span set:html={param.description} />
208+
<span set:html={normalizeP5ReferenceLinks(param.description)} />
200209
</div>
201210
</div>
202211
))}
@@ -212,7 +221,7 @@ const { showBanner, englishUrl } = checkTranslationBanner(
212221
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
213222
>
214223
{param.type && <span>{param.type}: </span>}
215-
<span set:html={param.description} />
224+
<span set:html={normalizeP5ReferenceLinks(param.description)} />
216225
</div>
217226
</div>
218227
)
@@ -232,7 +241,7 @@ const { showBanner, englishUrl } = checkTranslationBanner(
232241
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
233242
>
234243
{entry.data.return.type && <span>{entry.data.return.type}: </span>}
235-
<span set:html={entry.data.return.description} />
244+
<span set:html={normalizeP5ReferenceLinks(entry.data.return.description)} />
236245
</div>
237246
</div>
238247
</div>

0 commit comments

Comments
 (0)