de-jcup / eclipse-asciidoctor-editor

An eclipse editor for asciidoctor files
https://marketplace.eclipse.org/content/asciidoctor-editor
Other
58 stars 15 forks source link

wrong basedir in editor preview file? #469

Open Bananeweizen opened 1 year ago

Bananeweizen commented 1 year ago

Now that we discussed how to set variables in the .asciidoctorconfig, I was trying to make it work for different levels of nested directories containing adoc files, without putting a config file on each directory level. So instead of using

:imagedir: {asciidoctorconfigdir}

and having a separate config in dir, dir/nested, dir/nested/even/deeper etc., I was thinking of

:imagedir: {docdir}

and having only one config file on the project level. However, that doesn't work, and debugging the value of docdir in the preview also shows why: The preview doesn't use the file parent as base dir, but the grand parent. E.g. the generated adoc in the temp directory looks like this:

// origin :C:\dev\ascet\git\ascet\plugins\com.etas.esdl\documentation\user-guide-esdl\04-esdl-user-guide\062_integration_of_external_code.adoc
// editor :19acb74f-ab5a-37dd-8955-eba42ccb25a7
// basedir:C:\dev\ascet\git\ascet\plugins\com.etas.esdl\documentation\user-guide-esdl

// lots of things removed by me

include::04-esdl-user-guide/062_integration_of_external_code.adoc[]

Both the first 3 lines as well as the include statement at the end show that the base directory is not the immediate parent, but the grand-parent. And of course that works okay for the include statement itself (since it includes the grand-child instead of child), but it breaks any attempt of getting the direct parent folder of the adoc file. So I had to change the above config file to

:imagedir: {docdir}/04-esdl-user-guide

to make it work, but of course that is not a generic solution. Can we instead make the basedir the direct parent of the adoc file, please?

de-jcup commented 1 year ago

@Bananeweizen : Sorry for responding so late. Please do me a favor and write a short mail / or send me a message at twitter.

The base directory is always set to the root folder of the project where the last asciidoc file can be found. This is very necessary for a generic way, that all is working (at least for my documentation projects this works very well out -of -the box)

With Version 3.0.1 you can override attributes globally - see https://youtu.be/5OhWuJlMScA . So you have an alternative to overwrite, but of course this is cumbersome if you have many products/you have to change this very often.

I am thinking about an additional variable which can be used inside the global settings to handle this.

For example:

global setting (preferences) imageDir={asciidoctorparentdir}

asciidoctorparentdir would be injected by the editor automatically as an absolute path which represents always the parent folder of the origin editor file.

This would work globally, would exactly do what you want.

Because I try to be compatible with the origin .asciidoctorconfig syntax from @ahus1 (IntelliJ plugin) I am currently not sure, If I should provide asciidoctorparentdir also inside the .asciidoctorconfig file, because this would make it incompatible when there are mixed teams using eclipse and intellij.

@Bananeweizen : Do you think the asciidoctorparentdir attribute would solve your needs? @ahus1 : Do you think asciidoctorparentdir should be part of the "official" .asciidoctorconfig syntax (as a provided attribut injected by the IDE?). I want to be compatible with your implementation.

ahus1 commented 1 year ago

@Bananeweizen - if you could prepare a small example repository (or point me to a repository that is open source), I'd be happy to prepare a PR to fix the images showing in the preview in IntelliJ, and then we can compare it to the implementation in Eclipse. WDYT?

There's the following functionality in IntelliJ for setting folders around .asciidoctorconfig files:

{asciidoctorconfigdir} - will contain the absolute path of the folder were the .asciidoctorconfig file is located. This can be the parent folder of the project, or a subfolder. It is intended use is something like:

:imagesdir: {asciidoctorconfigdir}
// or...
:imagesdir: {asciidoctorconfigdir}/images
// or...
:imagesdir: {asciidoctorconfigdir}/..

inside of an .asciidoctorconfig file, or any other AsciiDoc file in the project.

In IntelliJ, the {docdir} is pointing to the folder where the current file is located...

I hope this information helps. More information is available here: https://intellij-asciidoc-plugin.ahus1.de/docs/users-guide/features/advanced/asciidoctorconfig-file.html

de-jcup commented 1 year ago

@ahus1 : Thank you very much.

After reading https://docs.asciidoctor.org/asciidoc/latest/attributes/document-attributes-ref/ looking for docdir it became clear that docdir is a read-only variable from asciidoctor .

I tested with #489 what the outputs are. After all: The problem is, that setting the base dir does influence the docdir attribute - or is always the same?