[go: up one dir, main page]

Consider supporting images with data-uri and inline svg

Both data-uri and inline svg currently don't work in similar ways. That data-uri doesn't work is documented and a feeble attempt is made to prevent its use; setting data-uri: true in the playbook allows investigation.

An inline svg image configured with

image::ab-to-inline.svg[opts=inline]

results in a stack trace:

SecurityError: Jail is not an absolute path: modules/ROOT/pages
    at Opal.send (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/opal-runtime/src/opal.js:1660:19)
    at Function.$$exception (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/opal-runtime/src/opal.js:5519:14)
    at $PathResolver.$$raise (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/opal-runtime/src/opal.js:5204:31)
    at $PathResolver.$$system_path (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:12144:18)
    at $Block.$$normalize_system_path (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:4962:37)
    at $Block.$$read_contents (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:5071:25)
    at Object.$$read_svg_contents (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:17236:33)
    at Object.$$image (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:16058:38)
    at Object.Opal.send (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/opal-runtime/src/opal.js:1660:19)
    at Object.convertImage (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/@antora/asciidoc-loader/lib/converter/html5.js:51:17)

Configuring data-uri in the playbook results in a similar stack trace:

SecurityError: Jail is not an absolute path: modules/ROOT/pages
    at Opal.send (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/opal-runtime/src/opal.js:1660:19)
    at Function.$$exception (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/opal-runtime/src/opal.js:5519:14)
    at $PathResolver.$$raise (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/opal-runtime/src/opal.js:5204:31)
    at $PathResolver.$$system_path (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:12144:18)
    at $Block.$$normalize_system_path (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:4962:37)
    at $Block.$$generate_data_uri (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:4861:29)
    at $Block.$$image_uri (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:4819:25)
    at Object.$$image (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/asciidoctor.js/dist/node/asciidoctor.js:16067:68)
    at Object.Opal.send (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/opal-runtime/src/opal.js:1660:19)
    at Object.convertImage (/Users/david/.nvm/versions/node/v10.16.3/lib/node_modules/@antora/site-generator-default/node_modules/@antora/asciidoc-loader/lib/converter/html5.js:51:17)

Putting in a bit of console logging I get:

$$image_uri(target_image, asset_dir_key) { target_image: 'ab-to-inline.svg', asset_dir_key: undefined }
$$generate_data_uri(target_image, asset_dir_key) { target_image: 'ab-to-inline.svg', asset_dir_key: 'imagesdir' }
$$normalize_system_path(target, start, jail, opts) { target: 'ab-to-inline.svg',
  start: '_images',
  jail: $NilClass { '$$id': 4, apply: [Function], call: [Function] },
  opts:
   $Hash {
     '$$smap': { target_name: 'image' },
     '$$map': [Object: null prototype] {},
     '$$keys': [ 'target_name' ] } }
$$normalize_system_path(target, start, jail, opts) end { target: 'ab-to-inline.svg',
  start: '_images',
  jail: 'modules/ROOT/pages',
  opts:
   $Hash {
     '$$smap': { target_name: 'image' },
     '$$map': [Object: null prototype] {},
     '$$keys': [ 'target_name' ] } }
$$system_path(target, start, jail, opts) { target: 'ab-to-inline.svg',
  start: '_images',
  jail: 'modules/ROOT/pages',
  opts:
   $Hash {
     '$$smap': { target_name: 'image' },
     '$$map': [Object: null prototype] {},
     '$$keys': [ 'target_name' ] } }

Evidently, there are several problems here:

  • asciidoctor is trying to read the image from the eventual target directory _images rather than the source directory where it actually is.
  • The jail (if it means what the name implies) doesn't include the images directory
  • absolute paths don't exist in antora's vfs

I'd think one way to resolve this problem would be for asciidoctor to rely on antora to read the image source or at least supply the file to be read, from the image coordinates. My understanding of the asciidoctor javascript is limited, but I don't see an obvious way to do this.

Edited by Dan Allen
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information