MCPcopy
hub / github.com/marktext/marktext / writeMarkdownFile

Function writeMarkdownFile

packages/desktop/src/main/filesystem/markdown.ts:69–86  ·  view source on GitHub ↗
(
  pathname: string,
  content: string,
  options: MarkdownDocumentOptions
)

Source from the content-addressed store, hash-verified

67 * Write the content into a file.
68 */
69export 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.

Callers 2

handleResponseForSaveFunction · 0.90
file.tsFile · 0.90

Calls 4

writeFileFunction · 0.90
convertLineEndingsFunction · 0.85
extnameMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected