Re: Single CSS for multiple, nested adoc files

Posted by mojavelinux on
URL: https://discuss.asciidoctor.org/Single-CSS-for-multiple-nested-adoc-files-tp552p556.html

Hey Christian,

Great question. I hadn't considered this scenario, so I'm glad you brought it forward. I really had to give it some thought.

Solution A ::

The simplest solution, naturally, is to embed the stylesheet into the document. This happens in Asciidoctor 0.1.4 by default (no linkcss or copycss flags).

 $ asciidoctor '**/*.adoc'

Solution B ::

Another solution is to provide an absolute path to the stylesheet, assuming you are serving the documents from a webserver. In this case, you'd have to handle copying the stylesheet to where you want it manually.

 $ asciidoctor -a stylesdir=/stylesheets -a linkcss -a copycss! '**/*.adoc'

However, those solutions may not match your requirements. Here are some that might.

Solution C ::

When you are running Asciidoctor once across a nested set of documents, it's currently not possible to specify a single relative path for the stylesdir attribute that would work for all documents, since the relative depth differs for documents in subdirectories. One way to solve this problem, as Jason suggested, is to maintain the path to the stylesdir in each document.

For 1.adoc and 2.adoc, that would be:

:stylesdir: ./stylesheets

For 3.adoc, that would be:

:stylesdir: ../stylesheets

Now the handling of the stylesheet and the reference in the document will behave as you expect.

Solution D ::

This got me thinking, though, that perhaps Asciidoctor should set an implicit attribute that passes the relative path from the document to the top-level when processing documents that span subdirectories. I'm thinking something like `docrootdir`. That way, the stylesdir attribute in the document is portable to where the document is placed.

:stylesdir: {docrootdir}/stylesheets

What do you think about that idea and, if we pursue it, the proposed name of the attribute. This would be a feature that is specific to Asciidoctor's ability to process documents in subdirectories. We could also set the same attribute in the Maven and Gradle plugins.

-Dan


On Tue, Sep 10, 2013 at 1:59 AM, ChrLipp [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello all!

I have nested adoc files in different directories, like

- src/asciidoc
  - 1.adoc
  - 2.adoc
  - nested <dir>
    - 3.adoc

When I set the copycss flag I end in having an asciidoc.css in each directory.
When I set the linkcss flag and copy the css manually in the root of the output directory, the css-link of 3.adoc is wrong (it expects the css in the same directory).

Is there a solution for that?
Kind regards, CL


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Single-CSS-for-multiple-nested-adoc-files-tp552.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | http://google.com/profiles/dan.j.allen