Download task_008/environment/code/convert.js from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 814 Bytes
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_008/environment/code/convert.js
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_008/environment/code/convert.js
-
curl -L -o convert.js https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_008/environment/code/convert.js
814 Bytes
| const fs = require('fs'); | |
| const path = require('path'); | |
| function convertMarkdownToPdf(inputPath, outputPath) { | |
| const markdown = fs.readFileSync(inputPath, 'utf8'); | |
| // TODO: render inline math such as \(\sqrt{2}\) as normal math. | |
| fs.writeFileSync(outputPath, '%PDF-1.4\n' + markdown + '\n%%EOF\n', 'utf8'); | |
| } | |
| function convertBatch(inputDir, outputDir) { | |
| fs.mkdirSync(outputDir, { recursive: true }); | |
| for (const file of fs.readdirSync(inputDir)) { | |
| if (file.endsWith('.md')) { | |
| convertMarkdownToPdf(path.join(inputDir, file), path.join(outputDir, file.replace(/\.md$/, '.pdf'))); | |
| } | |
| } | |
| } | |
| if (require.main === module) { | |
| const [inputDir = 'samples', outputDir = 'out'] = process.argv.slice(2); | |
| convertBatch(inputDir, outputDir); | |
| } | |
| module.exports = { convertMarkdownToPdf, convertBatch }; | |