File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed
routes/[pid=pid]/[org]/[repo]/[id=number] Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import type { Snippet } from " svelte" ;
3+ import type { Attachment } from " svelte/attachments" ;
4+ import { page } from " $app/state" ;
5+
6+ type Props = {
7+ children? : Snippet ;
8+ [k : string ]: unknown ;
9+ };
10+ let { children, ... rest }: Props = $props ();
11+
12+ const shorten: Attachment = node => {
13+ const originalText = node .innerText ;
14+ const shorteningCandidates = originalText
15+ .trim ()
16+ .match (/ https:\/\/ github. com\/ (\S + )\/ (\S + )\/ \S + \/ (\d + )/ );
17+ if (! shorteningCandidates || shorteningCandidates .length < 4 ) return ;
18+ const [wholeMatch, org, repo, number] = shorteningCandidates ;
19+ node .innerText =
20+ org === page .data .itemMetadata .org && repo === page .data .itemMetadata .repo
21+ ? originalText .replace (wholeMatch , ` #${number } ` )
22+ : originalText .replace (wholeMatch , ` ${org }/${repo }#${number } ` );
23+ };
24+ </script >
25+
26+ <a {...rest } {@attach shorten }>
27+ {@render children ?.()}
28+ </a >
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import type { Snippet } from " svelte" ;
3- import type { Action } from " svelte/action " ;
3+ import type { Attachment } from " svelte/attachments " ;
44 import { page } from " $app/state" ;
55
66 type Props = {
99
1010 let { children }: Props = $props ();
1111
12- const linkify: Action = node => {
12+ const linkify: Attachment = node => {
1313 let replaced = node .innerHTML ;
1414 const issuesCandidates = replaced .matchAll (/ #(\d + )/ g ) || [];
1515 for (let [wholeMatch, matchedGroup] of issuesCandidates ) {
2323 };
2424 </script >
2525
26- <p use: linkify >
26+ <p {@ attach linkify } >
2727 {@render children ?.()}
2828</p >
Original file line number Diff line number Diff line change 4646 import MarkdownRenderer from " $lib/components/MarkdownRenderer.svelte" ;
4747 import Step from " $lib/components/Step.svelte" ;
4848 import Steps from " $lib/components/Steps.svelte" ;
49+ import AnchorRenderer from " $lib/components/renderers/AnchorRenderer.svelte" ;
4950 import BodyRenderer from " $lib/components/renderers/BodyRenderer.svelte" ;
5051 import BottomCollapsible from " ./BottomCollapsible.svelte" ;
5152
256257 markdown ={entity .body || " _No description provided_" }
257258 parseRawHtml
258259 class =" max-w-full text-base"
259- additionalPlugins ={[{ renderer: { p: BodyRenderer } }, shikiPlugin ]}
260+ additionalPlugins ={[
261+ { renderer: { p: BodyRenderer , a: AnchorRenderer } },
262+ shikiPlugin
263+ ]}
260264 />
261265 </Accordion .Content >
262266 </Accordion .Item >
332336 markdown ={info .body || " _No description provided_" }
333337 parseRawHtml
334338 class =" max-w-full"
335- additionalPlugins ={[{ renderer: { p: BodyRenderer } }, shikiPlugin ]}
339+ additionalPlugins ={[{ renderer: { p: BodyRenderer , a: AnchorRenderer } }, shikiPlugin ]}
336340 />
337341 </div >
338342 </div >
You can’t perform that action at this time.
0 commit comments