UNPKG

confluence-exporter-tool

Version:

Convert full Confluence Storage Format XHTML to GitHub Markdown for Foam

29 lines (25 loc) 889 B
import fs from 'fs-extra'; import path from 'path'; import { convertXMLToMarkdown as convertXHTMLtoMarkdown } from '../lib/parser.js'; export async function convertFile(inputPath, outputPath, options = {}) { const { silent = false } = options; try { if (!fs.existsSync(inputPath)) { throw new Error(`File not found: ${inputPath}`); } const xhtml = await fs.readFile(inputPath, 'utf-8'); const markdown = convertXHTMLtoMarkdown(xhtml); await fs.ensureDir(path.dirname(outputPath)); await fs.writeFile(outputPath, markdown, 'utf-8'); if (!silent) { console.log(`Converted ${inputPath} to ${outputPath}`); } return markdown; } catch (err) { if (!silent) { console.error(`Error: ${err.message}`); } throw err; } } export default convertFile;