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

Specifying Environment variable not working in browser #476

Closed jcayouette closed 5 years ago

jcayouette commented 6 years ago

I am trying to setup specific rules for a github environment + asciidoctorjs plugin. When on github or when viewing adoc files on a local system using the asciidoctorjs browser extension I would like to prevent displaying includes and use cross references instead:

include::

I have the following so far:

ifndef::env-github,ENV?[]
include::quickstart_overview.adoc[leveloffset=1]
endif::[]
ifdef::env-github,backend-html5[]
<<quickstart_overview.adoc#overview, Overview>>
endif::[]

This works for github. But when I view the same file in a browser using the asciidoctorjs extension I get the following result:

quickstart_overview.adoc
Overview

Which env should I specify in the first ifndef to prevent loading of includes in asciidoctorjs within the browser?

Is this the correct way to go about this? Or could you suggest an alternative?

Best!

ggrossetie commented 6 years ago

Hello @jcayouette I believe your issue is related to the Asciidoctor browser extension ? If so could you please open your issue on https://github.com/asciidoctor/asciidoctor-browser-extension ? Thanks :smiley:

mojavelinux commented 6 years ago

On top of that, environment variables are not accessible to the document.

ggrossetie commented 5 years ago

Which env should I specify in the first ifndef to prevent loading of includes in asciidoctorjs within the browser?

I guess you could define an attribute in the browser extension:

env-browser

@jcayouette Does it answer your question ? Can we close this issue ?

ggrossetie commented 5 years ago

Closing, please join http://gitter.im/asciidoctor/asciidoctor.js if we didn't answer your question.

yoarch commented 4 years ago

Hi, I don't want to necro bump this post but I have the exact same issue. I need the {user-home} environment variable in my asciidoc scripts, it works perfectly except when I render with Brave (close to Chromium). Tried to add environment variable in the asciidoctor.js as suggested but unsuccessful. Any more ideas?

ggrossetie commented 4 years ago

@yoarch Environment variables are not available in a browser environment. The value of the built-in attribute user-home in a browser environment will be ..

You will need to explicitly define the value using a custom attribute: my-user-home=/home/guillaume

Capture d’écran 2020-08-12 à 13 32 09 Capture d’écran 2020-08-12 à 13 32 27
yoarch commented 4 years ago

Hi Guillaume, Thanks for the reply. Yes, indeed. It works. Thanks for your time.

mojavelinux commented 4 years ago

@Mogztter It definitely seems like it should be possible to set user-home manually using the options page. Do you see a problem with that idea?

ggrossetie commented 4 years ago

@mojavelinux I don't recall, is it possible to override a built-in attribute? https://github.com/asciidoctor/asciidoctor/blob/4284a176fac29bdde62288f13e7ebb18defeb9aa/lib/asciidoctor/document.rb#L374

mojavelinux commented 4 years ago

Oh, duh. You're right. Certain built-in attributes cannot be overridden even from the commandline. I think it should be possible to override user-home because we cannot be sure the inherent value is correct. Let's take that up in core.

ggrossetie commented 4 years ago

Follow-up issue: https://github.com/asciidoctor/asciidoctor/issues/3732