Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/layouts/ReferenceItemLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ const descriptionParts = description.split(
/(<pre><code class="language-js(?: example)?">[\s\S]+?<\/code><\/pre>)/gm
);

// Normalizes malformed p5.* reference anchors (e.g. "#/p5.Element")
// to proper reference routes ("/reference/p5/p5.Element/")
function normalizeP5ReferenceLinks(html: string | undefined): string | undefined {
if (!html) return html;
return html.replace(
/href="#\/(p5\.[^"]+)"/g,
'href="/reference/p5/$1/"'
);
}
---

<Head title={entry.data.title} locale={currentLocale} />
Expand Down Expand Up @@ -208,7 +217,7 @@ const descriptionParts = description.split(
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
>
{param.type && <span>{param.type}: </span>}
<span set:html={param.description} />
<span set:html={normalizeP5ReferenceLinks(param.description)} />
</div>
</div>
))}
Expand All @@ -226,7 +235,7 @@ const descriptionParts = description.split(
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
>
{param.type && <span>{param.type}: </span>}
<span set:html={param.description} />
<span set:html={normalizeP5ReferenceLinks(param.description)} />
</div>
</div>
)
Expand All @@ -246,7 +255,7 @@ const descriptionParts = description.split(
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
>
{entry.data.return.type && <span>{entry.data.return.type}: </span>}
<span set:html={entry.data.return.description} />
<span set:html={normalizeP5ReferenceLinks(entry.data.return.description)} />
</div>
</div>
</div>
Expand Down