MCPcopy
hub / github.com/refined-github/refined-github / embedGist

Function embedGist

source/features/embed-gist-inline.tsx:25–59  ·  view source on GitHub ↗
(link: HTMLAnchorElement)

Source from the content-addressed store, hash-verified

23 link.textContent.trim() === link.parentElement!.textContent.trim();
24
25async function embedGist(link: HTMLAnchorElement): Promise<void> {
26 const info = <em> (loading)</em>;
27 link.after(info);
28
29 try {
30 const gistData = await fetchGist(link.href);
31 if (gistData.div.length > 10_000) {
32 info.textContent = ' (too large to embed)';
33 return;
34 }
35
36 const fileCount: number = gistData.files.length;
37 if (fileCount > 1) {
38 info.textContent = ` (${fileCount} files)`;
39 } else {
40 const container = <div />;
41 container.attachShadow({mode: 'open'}).append(
42 <style>{`
43 .gist .gist-data {
44 max-height: 16em;
45 overflow-y: auto;
46 }
47 `}
48 </style>,
49 <link rel="stylesheet" href={gistData.stylesheet} />,
50 domify.one(gistData.div)!,
51 );
52 link.parentElement!.after(container);
53 info.remove();
54 }
55 } catch (error) {
56 info.remove();
57 throw error;
58 }
59}
60
61function init(signal: AbortSignal): void {
62 observe(standaloneGistLinkInMarkdown, link => {

Callers 1

initFunction · 0.85

Calls 2

removeMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected