Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/dev/s2-docs/src/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function renderHast(node: HastNode | HastTextNode, key: string, links?: Links, i

// CodeProps includes the indent and newlines in case there are no props to show.
if (node.tagName === 'div' && typeof childArray[0] === 'string' && /^\s+$/.test(childArray[0]) && React.isValidElement(childArray[1]) && childArray[1].type === CodeProps) {
children = childArray[1];
children = childArray.slice(1);
}

let tagName: any = node.tagName;
Expand Down
14 changes: 10 additions & 4 deletions packages/dev/s2-docs/src/MarkdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface MarkdownMenuProps {
export function MarkdownMenu({url}: MarkdownMenuProps) {
let mdUrl = (url ?? '').replace(/\.html?$/i, '') + '.md';
let [isCopied, setIsCopied] = useState(false);
let [isPending, setPending] = useState(false);
let timeout = useRef<ReturnType<typeof setTimeout> | null>(null);

let pageUrl = typeof window !== 'undefined' && url ? new URL(url, window.location.origin).href : url ?? '';
Expand All @@ -38,20 +39,25 @@ export function MarkdownMenu({url}: MarkdownMenuProps) {
}
if (typeof navigator !== 'undefined' && navigator.clipboard) {
try {
let response = await fetch(mdUrl);
let markdown = await response.text();
await navigator.clipboard.writeText(markdown);
setPending(true);
await navigator.clipboard.write([
new ClipboardItem({
['text/plain']: fetch(mdUrl).then(res => res.text())
})
]);
setIsCopied(true);
timeout.current = setTimeout(() => setIsCopied(false), 2000);
} catch {
ToastQueue.negative('Failed to copy markdown.');
} finally {
setPending(false);
}
}
}, [mdUrl]);

return (
<div className={style({display: 'flex', justifyContent: 'space-between', paddingX: 4, paddingBottom: 16})}>
<ActionButton isQuiet size="M" onPress={handleCopy}>
<ActionButton isQuiet size="M" onPress={handleCopy} isPending={isPending}>
{isCopied ? <CheckmarkCircle /> : <Copy />}
<Text>Copy for LLM</Text>
</ActionButton>
Expand Down
Loading