-
-
Notifications
You must be signed in to change notification settings - Fork 145
Description
Background
I am creating a SvelteKit site and have a /docs route that is using Asciidoctor.js to convert some .adoc files to HTML as part of the build process, then using the resulting HTML in my pages. Overall this works fine, however I have recently run in to an issue with using the include directive to fetch some remote data that we use to build tables in some of our docs.
Problem Description
We use an attribute in our documents to optionally include remote content as we build different versions of our documentation. When this attribute is set, we try to load our data in the table. If it is not, we skip this and just render some placeholder text in our table. In our old site using the Ruby version of Asciidoctor and built via Hugo, this works fine. However in Asciidoctor.js this results in an error. I've provided some configuration info and the error output below.
Example Adoc file
This is an example asciidoc file where we attempt to load this remote content. This file gets read as raw text and passed to the Asciidoctor.js convert method.
:dataset: true
ifeval::[{dataset} == true]
[#table-id]
.Test Results
[cols="2*^", options="header"]
|===
include::https://files.ourserver.com/some-file.csv[]
|===
endif::[]
ifeval::[{dataset} == false]
[#table-id]
.Test Results Missing
[cols="1*^"]
|====
a|**Missing Data**
|====
endif::[]
Asciidoctor.js Setup
This gives a brief overview of how I am using Asciidoctor.js to convert my files to HTML. This is in the +layout.server.ts file specified by Svelte, though I don't believe this bug should be framework specific.
import AsciiDocProcessor from "@asciidoctor/core";
//Initialize Asciidoctor.js
const processor = AsciiDocProcessor();
function processAsciidoc(page)
{
const options = {
'standalone':false,
'safe':'safe',
'attributes': {
'allow-uri-read':'',
'skip-front-matter':true,
'imagesdir': "https://files.ourserver.com/images"
'attribute-missing': "warn"
}
//page.raw here would be the raw contents of the example adoc file above
const html = processor.convert(page.raw, options);
page.html = html
}
// This part is really only relevant for Svelte. I'm skipping a lot of logic here
export async function load({url, parent})
{
let page = await fetchMyPageObject();
processAsciidoc(page);
}
Error Output
Trying to process the blocks in the example adoc file above results in this error if :dataset: is true and the include directive is processed. I do not believe this is an issue with my implementation, though I could be mistaken.
TypeError: Cannot create property '$$meta' on string 'https://files.ourserver.com/some-file.csv'
at $prop (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:164:20)
at set_meta (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:848:7)
at Opal.build_object_singleton_class (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:919:5)
at Opal.get_singleton_class (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:839:19)
at String.$$singleton_class (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:8458:19)
at String.$$extend (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:4954:28)
at Function.$$parse (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:739:18)
at klass.$$resolve_include_path (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:12067:30)
at klass.$$preprocess_include_directive (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:11784:21)
at klass.$$process_line (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:11584:37)
at klass.$$peek_line (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:10859:38)
at Opal.send2 (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:1921:17)
at klass.$$peek_line (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:11374:29)
at klass.$PreprocessorReader_has_more_lines$ques$9 (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:11350:26)
at klass.$$read_line (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:10906:86)
at $$4 (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:10881:74)
at Number.$$times (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:17910:9)
at Opal.send2 (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:1921:17)
at Opal.send (file:///workspace/www/node_modules/@asciidoctor/opal-runtime/src/opal.js:1909:17)
at file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:10878:68
at klass.$$peek_lines (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:10892:12)
at Function.$Parser_is_next_line_section$ques$17 (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:9228:31)
at Function.$$next_section (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:7884:67)
at Function.$$next_section (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:7904:25)
at Function.$$parse (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:7645:23)
at klass.$$parse (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:6333:24)
at Function.$$load (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:13406:137)
at Function.$$convert (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:13513:20)
at Asciidoctor.convert (file:///workspace/www/node_modules/@asciidoctor/core/dist/node/asciidoctor.js:17860:23)
at processAsciidoc (/workspace/www/src/routes/docs/+layout.server.ts:146:26)
at load (/workspace/www/src/routes/docs/+layout.server.ts:115:5)
at async Module.load_server_data (/workspace/www/node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js:51:17)
at async eval (/workspace/www/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:141:13)
Other Notes
Svelte does place some restrictions on the fetch API in the Svelte SSR context, however from reading other issues and looking over the source, it appears that Asciidoctor.js is using the XMLHttpRequest API to process these remote includes, which is allowed in that context by Svelte. So from everything I'm seeing this shouldn't be an implementation issue.
The files are also publicly available at the URL provided and have valid content, though they are not adoc files.
Any help would be appreciated.