This commit is contained in:
@@ -72,8 +72,27 @@ export function resolveArticleActionState(
|
||||
export function buildArticleClipboardContent(
|
||||
detail: Pick<ArticleDetail, 'title' | 'markdown_content'>,
|
||||
): string {
|
||||
return [detail.title ? `# ${detail.title}` : '', detail.markdown_content ?? '']
|
||||
.filter(Boolean)
|
||||
.join('\n\n')
|
||||
.trim()
|
||||
const title = detail.title?.trim() ?? ''
|
||||
const markdown = detail.markdown_content?.trim() ?? ''
|
||||
|
||||
if (!title) {
|
||||
return markdown
|
||||
}
|
||||
|
||||
if (!markdown) {
|
||||
return `# ${title}`
|
||||
}
|
||||
|
||||
if (getLeadingH1Text(markdown) === title) {
|
||||
return markdown
|
||||
}
|
||||
|
||||
return [`# ${title}`, markdown].join('\n\n').trim()
|
||||
}
|
||||
|
||||
function getLeadingH1Text(markdown: string): string | null {
|
||||
const normalizedMarkdown = markdown.replace(/^\uFEFF/, '').trimStart()
|
||||
const firstLine = normalizedMarkdown.split(/\r?\n/, 1)[0]?.trim() ?? ''
|
||||
const match = firstLine.match(/^#\s+(.+?)\s*#*$/)
|
||||
return match?.[1]?.trim() ?? null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user