Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API compatibility with asciidoctor-pdf Ruby version #155

Closed
danyill opened this issue Jan 22, 2020 · 6 comments
Closed

API compatibility with asciidoctor-pdf Ruby version #155

danyill opened this issue Jan 22, 2020 · 6 comments

Comments

@danyill
Copy link
Sponsor Contributor

danyill commented Jan 22, 2020

I wanted to recommend this project as a drop-in for the Ruby asciidoctor-pdf for the vscode extension (see this issue asciidoctor/asciidoctor-vscode#239) but found it didn't quite work.

The Ruby version has the following:

 -o, --out-file FILE              output file (default: based on path of input file); use - to output to STDOUT

Whereas the js version has:

  --out-file, -o          output file (default: based on path of input file) use '' to output to STDOUT         [string]

Would you be receptive to using - to enhance compatibility and portability with the Ruby version?

@danyill
Copy link
Sponsor Contributor Author

danyill commented Jan 22, 2020

I may be getting this wrong.

I think asciidoctor-pdf Ruby supports the option - being passed by itself (not in connection with -o) for reading from STDIN but currently the js version doesn't support this.

It doesn't seem to be documented for the Ruby version either but is depended on in the asciidoctor-vscode extension (here)

@danyill
Copy link
Sponsor Contributor Author

danyill commented Jan 22, 2020

Ah. The documentation is in the user manual: https://asciidoctor.org/docs/user-manual/#piping-content-through-the-cli

@ggrossetie
Copy link
Owner

ggrossetie commented Jan 22, 2020

It should work both ways, reading from stdin and writing to stdout.

We might need to port this code: https://github.com/asciidoctor/asciidoctor-cli.js/blob/693a9910d4d0a59103b7590ea57dbddf197d4135/lib/invoker.js#L26

@ggrossetie
Copy link
Owner

Actually there's an issue here:

https://github.com/Mogztter/asciidoctor-pdf.js/blob/3da382ef961dc08ce5f7e86df216251c4407d2c3/lib/converter.js#L101

pdf object is an Uint8Array and toString will return a string representing the specified array and its elements (not the actual data).
We probably need to convert it to a binary string:

function convertUint8ArrayToBinaryString(u8Array) {
  var i, len = u8Array.length, b_str = "";
  for (i=0; i<len; i++) {
    b_str += String.fromCharCode(u8Array[i]);
  }
  return b_str;
}

@danyill To be clear, you want to write the PDF to stdout? or you want to read the AsciiDoc content from stdin? or maybe both?

@danyill
Copy link
Sponsor Contributor Author

danyill commented Jan 23, 2020

Well at the moment the vs-code extension only uses stdin to pipe the Asciidoc contents in and then writes to a file. Perhaps it makes sense to have stdout too (I'm not sure).

I've been looking at the way reading from stdin is supported. It seems to require that - is the last argument provided.

See:
https://github.com/asciidoctor/asciidoctor-cli.js/blob/693a9910d4d0a59103b7590ea57dbddf197d4135/lib/options.js#L223-L237

I did a PR with "something like" the changes that are necessary.

@danyill
Copy link
Sponsor Contributor Author

danyill commented Jan 28, 2020

Thanks @Mogztter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants