( pathname: string, content: string, options: MarkdownDocumentOptions )
| 67 | * Write the content into a file. |
| 68 | */ |
| 69 | export const writeMarkdownFile = ( |
| 70 | pathname: string, |
| 71 | content: string, |
| 72 | options: MarkdownDocumentOptions |
| 73 | ): Promise<void> => { |
| 74 | const { adjustLineEndingOnSave, lineEnding } = options |
| 75 | const { encoding, isBom } = options.encoding |
| 76 | const extension = path.extname(pathname) || '.md' |
| 77 | |
| 78 | if (adjustLineEndingOnSave) { |
| 79 | content = convertLineEndings(content, lineEnding) |
| 80 | } |
| 81 | |
| 82 | const buffer = iconv.encode(content, encoding, { addBOM: isBom }) |
| 83 | |
| 84 | // TODO(@fxha): "safeSaveDocuments" using temporary file and rename syscall. |
| 85 | return writeFile(pathname, buffer, extension, undefined) |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Reads the contents of a markdown file. |
no test coverage detected