Files
outline/shared/utils/MarkdownHelper.ts
Tom Moor 3f3d7b4978 Add 'Copy as Markdown' action
Remove smart quotes from Markdown export, closes #5303
2023-12-09 15:00:33 -05:00

30 lines
710 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
interface DocumentInterface {
emoji?: string | null;
title: string;
text: string;
}
export default class MarkdownHelper {
/**
* Returns the document as cleaned Markdown for export.
*
* @param document The document or revision to convert
* @returns The document title and content as a Markdown string
*/
static toMarkdown(document: DocumentInterface) {
const text = document.text
.replace(/\n\\\n/g, "\n\n")
.replace(/“/g, '"')
.replace(/”/g, '"')
.replace(//g, "'")
.replace(//g, "'")
.trim();
const title = `${document.emoji ? document.emoji + " " : ""}${
document.title
}`;
return `# ${title}\n\n${text}`;
}
}