mdpdf icon indicating copy to clipboard operation
mdpdf copied to clipboard

mdpdf console command fails on windows if the markdown file is within a folder that has a pound sign (#)

Open futuremotiondev opened this issue 2 years ago • 1 comments

Command: mdpdf "D:\Dev\00 Research\C#\C# Cheat Sheet.md" --style C:\bin\github.css

Error:

12-24 03:49:32 C:\Users\username\Desktop> mdpdf "D:\Dev\00 Research\C#\C# Cheat Sheet.md" --style C:\bin\github.css
Error: net::ERR_FILE_NOT_FOUND at file:D:\Dev\00 Research\C#\_temp.html
    at navigate (C:\Users\username\AppData\Roaming\nvm\v20.10.0\node_modules\mdpdf\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:194:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async FrameManager.navigateFrame (C:\Users\username\AppData\Roaming\nvm\v20.10.0\node_modules\mdpdf\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:170:21)
    at async Frame.goto (C:\Users\username\AppData\Roaming\nvm\v20.10.0\node_modules\mdpdf\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:589:16)
    at async Page.goto (C:\Users\username\AppData\Roaming\nvm\v20.10.0\node_modules\mdpdf\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:1089:16)
    at async C:\Users\username\AppData\Roaming\nvm\v20.10.0\node_modules\mdpdf\src\index.js:174:7

Despite the error stating ERR_FILE_NOT_FOUND at file:D:\Dev\00 Research\C#\_temp.html, _temp.html IS actually created in the target folder. But node seems unable to find it?

Hopefully this is an easy fix.

futuremotiondev avatar Dec 24 '23 09:12 futuremotiondev

Hey, thanks for reporting this. It looks like the error is coming from the Puppeteer call to get chrome to navigate to the intermediary html file. I'm not entirely sure why Chrome would be unhappy with that path. I imagine it's because the result of the resolve call to get the file path isn't quite fit for a URL on windows. Looking at that URL, it looks like it's missing some prefix /'s at least.

Unfortunately I don't have access to a windows machine which I can install nodejs on at the moment as I only use linux and macos these days. If that changes I'll give this a crack but I can't promise anything any time soon.

If you'd like to open a PR, I'd be more than happy to review and merge. I suspect the change will be somewhere around https://github.com/BlueHatbRit/mdpdf/blob/01f2e38e1e85b0839de3c89d0d24c18b20aae5fa/src/index.js#L175 where we get the file path.

elliotblackburn avatar Dec 31 '23 18:12 elliotblackburn