elliotblackburn / mdpdf

Markdown to PDF command line app with support for stylesheets
https://npmjs.com/package/mdpdf
Apache License 2.0
712 stars 46 forks source link

/usr/local/bin/mdpdf uses CRLF linebreaks #70

Closed CTXz closed 10 months ago

CTXz commented 5 years ago

When installing mdpdf via:

# npm install mdpdf -g --unsafe-perm=true

on Ubuntu 18.04 LTS with NPM version 3.5.2 I receive the following error when I attempt to execute mdpdf:

$ mdpdf
/usr/bin/env: ‘node\r’: No such file or directory

As it turns out the script under /usr/local/bin/mdpdf uses CRLF linebreaks. Changing it to LF in an editor, such as Atom, fixes this issue.

Oddly, this issue does not occur when installing mdpdf from source.

elliotblackburn commented 5 years ago

Strange, it looks fine for me when I clone it down. I'll check over my git settings and see what might be the problem but the fact that it's okay when you clone and build from source, makes me wonder if this is actually an issue with mdpdf.

None the less, I shall check!

elliotblackburn commented 5 years ago

I've just cloned the repository fresh and checked the line endings:

in code/
› g clone git@github.com:BlueHatbRit/mdpdf.git
Cloning into 'mdpdf'...
remote: Enumerating objects: 77, done.
remote: Counting objects: 100% (77/77), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 643 (delta 32), reused 61 (delta 21), pack-reused 566
Receiving objects: 100% (643/643), 1.49 MiB | 3.13 MiB/s, done.
Resolving deltas: 100% (292/292), done.

in code/
› cd mdpdf

in mdpdf/ on master
› file bin/index.js
bin/index.js: a /usr/bin/env node script text executable, UTF-8 Unicode text

I also downloaded the repo as a zip (to avoid git's tomfoolery with line endings), ran the same command and the line endings are indeed only LF. So it would seem that the line endings are correct, and as I usually develop on macos/linux I'd be incline to think that our line endings are correct.

Perhaps this is in fact an npm issue? I'll do some digging and see what I can find but I'm not massively hopeful when it comes to line endings 😂

abegosum commented 5 years ago

I can confirm, I also can't use the npm installation out of the box due to line breaks breaking the shebang execution. After upgrading, I receive the error : No such file or directory on CentOS 7. Running dos2unix on /usr/lib/node_modules/mdpdf/bin/index.js resolves the issue. Below are my troubleshooting steps.

[abond@hqitbuild01 ~]$ mdpdf
: No such file or directory
[abond@hqitbuild01 ~]$ node /usr/lib/node_modules/mdpdf/bin/index.js 

  Markdown to PDF command line converter

     Usage:
         $ mdpdf <source> [<destination>] [options]

     <source> must be a markdown file, with the extension '.md'.

     Examples:
         $ mdpdf README.md
         $ mdpdf README.md --style=styles.css --header=header.hbs --h-height=22mm
         $ mdpdf README.md --footer=footer.hbs --f-height=22mm --debug
         $ mdpdf README.md --border-left=30mm

     Options:
         --style=<filename>           A single css stylesheet you wish to apply to the PDF
         --header=<filename>          A HTML (.html) file to inject into the header of the PDF
         --h-height=<height>          The height of the header section
         --footer=<filename>          A HTML (.html) file to inject into the footer of the PDF
         --f-height=<height>          The height of the footer section
         --border=<size>              Border (top, left, bottom, right; default: 20mm)
         --border-top=<size>          Top border (default: 20mm)
         --border-left=<size>         Left border (default: 20mm)
         --border-bottom=<size>       Bottom border (default: 20mm)
         --border-right=<size>        Right border (default: 20mm)
         --no-emoji                   Disables emoji conversions
         --debug                      Save the generated html for debugging
         --help                       Display this menu
         --version                    Display the application version
         --format=<format>            PDF size format: A3, A4, A5, Legal, Letter, Tabloid (Default: A4)
         --orientation=<orientation>  PDF orientation: portrait or landscape (Default: portrait)

    Length parameters (<height> and <size>) require a unit. Valid units are mm, cm, in and px.

  Global Settings:
    You can also set a global default stylesheet by setting the MDPDF_STYLES environment
    variable as the path to your single css stylesheet. The --style flag will override this.
[abond@hqitbuild01 ~]$ sudo dos2unix /usr/lib/node_modules/mdpdf/bin/index.js 
dos2unix: converting file /usr/lib/node_modules/mdpdf/bin/index.js to Unix format ...
[abond@hqitbuild01 ~]$ mdpdf

  Markdown to PDF command line converter

     Usage:
         $ mdpdf <source> [<destination>] [options]

     <source> must be a markdown file, with the extension '.md'.

     Examples:
         $ mdpdf README.md
         $ mdpdf README.md --style=styles.css --header=header.hbs --h-height=22mm
         $ mdpdf README.md --footer=footer.hbs --f-height=22mm --debug
         $ mdpdf README.md --border-left=30mm

     Options:
         --style=<filename>           A single css stylesheet you wish to apply to the PDF
         --header=<filename>          A HTML (.html) file to inject into the header of the PDF
         --h-height=<height>          The height of the header section
         --footer=<filename>          A HTML (.html) file to inject into the footer of the PDF
         --f-height=<height>          The height of the footer section
         --border=<size>              Border (top, left, bottom, right; default: 20mm)
         --border-top=<size>          Top border (default: 20mm)
         --border-left=<size>         Left border (default: 20mm)
         --border-bottom=<size>       Bottom border (default: 20mm)
         --border-right=<size>        Right border (default: 20mm)
         --no-emoji                   Disables emoji conversions
         --debug                      Save the generated html for debugging
         --help                       Display this menu
         --version                    Display the application version
         --format=<format>            PDF size format: A3, A4, A5, Legal, Letter, Tabloid (Default: A4)
         --orientation=<orientation>  PDF orientation: portrait or landscape (Default: portrait)

    Length parameters (<height> and <size>) require a unit. Valid units are mm, cm, in and px.

  Global Settings:
    You can also set a global default stylesheet by setting the MDPDF_STYLES environment
    variable as the path to your single css stylesheet. The --style flag will override this.
elliotblackburn commented 5 years ago

I honestly have no idea how this is happening, the files are all lf line endings when checked out in git. I only develop on this project on unix machines. I'll take another crack but this is starting to sound like an NPM issue rather than one caused by MDPDF :/

Thanks for the troubleshooting steps. I'll see what I can find with them!