diff --git a/src/components/CopyMarkdownButton.tsx b/src/components/CopyMarkdownButton.tsx index 6d8fba82d..704134d52 100644 --- a/src/components/CopyMarkdownButton.tsx +++ b/src/components/CopyMarkdownButton.tsx @@ -54,48 +54,52 @@ export function CopyMarkdownButton({ const cached = cache.get(url) if (cached) { - navigator.clipboard.writeText(cached) - notify( -
-
Copied markdown
-
- Source content copied from cache + navigator.clipboard.writeText(cached).then(() => { + notify( +
+
Copied markdown
+
+ Source content copied from cache +
-
- ) + ) + }) } else { fetch(url) - .then((response) => response.text()) + .then((response) => { + if (!response.ok) { + throw new Error('Fetch failed') + } + return response.text() + }) .then((content) => { cache.set(url, content) - return navigator.clipboard.writeText(content) - }) - .then(() => { - notify( -
-
Copied markdown
-
- Source content copied from GitHub + return navigator.clipboard.writeText(content).then(() => { + notify( +
+
Copied markdown
+
+ Source content copied from GitHub +
-
- ) + ) + }) }) .catch(() => { // fallback: try to copy current page content if available const pageContent = document.querySelector('.styled-markdown-content')?.textContent || '' - return navigator.clipboard.writeText(pageContent) - }) - .then(() => { - notify( -
-
Copied markdown
-
- Fallback: copied rendered page content + navigator.clipboard.writeText(pageContent).then(() => { + notify( +
+
Copied markdown
+
+ Fallback: copied rendered page content +
-
- ) + ) + }) }) } })