Skip to content
Open
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
18 changes: 12 additions & 6 deletions src/components/CopyMarkdownButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ export default function CopyMarkdownButton() {

const copyMarkdown = async () => {
try {
// Get the main article content
const article = document.querySelector('article');
if (!article) return;
// Get the main content with Docusaurus-specific selectors
const contentElement = document.querySelector('.theme-doc-markdown') ||
document.querySelector('article');

// Get the markdown content from the page
const title = document.querySelector('h1')?.textContent || '';
const content = article.innerText;
if (!contentElement) return;

// Get the title
const title = document.querySelector('.theme-doc-markdown h1')?.textContent ||
document.querySelector('h1')?.textContent ||
document.title || '';

// Get the content text
const content = contentElement.innerText || contentElement.textContent || '';

// Format as markdown
const markdown = `# ${title}\n\n${content}`;
Expand Down