asciidoctor / asciidoctor.js

:scroll: A JavaScript port of Asciidoctor, a modern implementation of AsciiDoc
https://asciidoctor.org
MIT License
729 stars 135 forks source link

Question regarding data-uri #718

Closed lask79 closed 4 years ago

lask79 commented 5 years ago

Hi,

I am currently playing around with Gatsby and its asciidoc transformer which uses asciidoctor.js to generate the html from asciidoc files. I am now trying to embed all of the images via data-uri but it does not seem to work. I set the :data-uri: and also tried to pass the data-uri:true as an option.

When I take a look at its implementation it first calls: asciidoc.load(content, pluginOptions) see here

and later calls: const html = doc.convert() see here

Is the API here used correctly to support the data-uri feature for embedding all linked images?

The used asciidoctorjs version is 1.5.9.

Regards Lasse

lask79 commented 5 years ago

I found out that i have to use safe: 'safe', so that asciidoctor at least tries to embed the images but now those images are still missing. I only see in html that instead of the url a base64 is added but it is completely empty.

Any ideas?

ggrossetie commented 5 years ago

Hello @lask79, could you please share a sample document ?

Also could you please try to convert your document using Asciidoctor.js 2.0.0 ?

$ npm -i asciidoctor
$ asciidoctor --version
$ asciidoctor -a data-uri --safe-mode safe doc.adoc

Thanks

ggrossetie commented 5 years ago

For reference, we have a few tests to make sure that Asciidoctor.js can embed an image when data-uri is defined:

https://github.com/asciidoctor/asciidoctor.js/blob/fee9f3d62f7e814a00aa74b35e096f1ec262a45f/packages/core/spec/share/asciidoctor-spec.js#L915-L949

And here's the code that should be used to fetch a remote image and generate the base64: https://github.com/asciidoctor/asciidoctor.js/blob/fee9f3d62f7e814a00aa74b35e096f1ec262a45f/packages/core/lib/asciidoctor/js/asciidoctor_ext/node/abstract_node.rb#L6

Any warning in the console ?

lask79 commented 5 years ago

I found the issue. The :docdir: was pointing to the root of the gatsby project. As soon as I set that value to the directory where the asciidoc file is located it works. Please close this issue.

ggrossetie commented 5 years ago

I found the issue. The :docdir: was pointing to the root of the gatsby project. As soon as I set that value to the directory where the asciidoc file is located it works.

Cool, could you please share your configuration in order to help other users stumbling upon this issue ?

I'm also a bit worried that Asciidoctor.js didn't log a warning message and just returned an empty URL :thinking:

ggrossetie commented 5 years ago

The scheme part is defined as:

Each URI begins with a scheme name that refers to a specification for assigning identifiers within that scheme. As such, the URI syntax is a federated and extensible naming system wherein each scheme's specification may further restrict the syntax and semantics of identifiers using that scheme.

Scheme names consist of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus ("+"), period ("."), or hyphen ("-"). Although schemes are case- insensitive, the canonical form is lowercase and documents that specify schemes must do so with lowercase letters. An implementation should accept uppercase letters as equivalent to lowercase in scheme names (e.g., allow "HTTP" as well as "http") for the sake of robustness but should only produce lowercase scheme names for consistency.

 scheme      = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

https://tools.ietf.org/html/rfc3986#section-3.1