Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheriting included attributes #41

Open
bostrt opened this issue Jul 28, 2023 · 9 comments
Open

Inheriting included attributes #41

bostrt opened this issue Jul 28, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@bostrt
Copy link

bostrt commented Jul 28, 2023

Hello! I'm a new user to asciidoctor and asciidoctor-multipage so please bare with me 😅 . I have a main.adoc where I'm including some attributes use throughout. For example:

= My page

include::data/shared-metadata.adoc[]
{metadata_0}

== Page 1
{metadata_1}

== Page 2
{metadata_2}

data/shared-metadata.adoc contains the attributes referenced.

When I build the adoc normally, they are rendered as expected. However, when I build using asciidoctor-multipage, The resulting output only shows attributes on the main page (metadata_0) but pages 1 and 2 only show the place holders.

asciidoctor -r ~/code/asciidoctor-multipage/lib/asciidoctor-multipage.rb -b multipage_html5 main.adoc -D out

Is it possible for the included adoc to be inherited and render those attributes in other HTML pages?

@owenh000
Copy link
Owner

This will work if you define the attributes in the document header, like this:

= My page
include::data/shared-metadata.adoc[]

{metadata_0}

== Page 1
{metadata_1}

== Page 2
{metadata_2}

@bostrt
Copy link
Author

bostrt commented Aug 16, 2023

Yes! Thank you and that solves it 👍

@bostrt bostrt closed this as completed Aug 16, 2023
@bostrt
Copy link
Author

bostrt commented Aug 16, 2023

Apologies, but after some more testing, I tend to see defining the attributes include in document header was a workaround to the root issue. I guess I expect the asciidoc to build the same no matter if I am using multipage or not.

Does the workaround you mentioned have to do with a technical limitation of the asciidoctor API you extend and the point at which attributes are able to be inherited?

@bostrt bostrt reopened this Aug 16, 2023
@owenh000
Copy link
Owner

I guess I expect the asciidoc to build the same no matter if I am using multipage or not.

Well, that seems reasonable, but it's not perfect. (And we are also literally expecting it to not build the same, in that we want it to generate multiple HTML output pages rather than just one.)

Does the workaround you mentioned have to do with a technical limitation of the asciidoctor API you extend and the point at which attributes are able to be inherited?

I suppose so, but I cannot answer that for sure. I do know that asciidoctor-multipage works by taking the single, entire Asciidoctor::Document object (of which there is normally only one) and creates multiple Asciidoctor::Document objects (one for each page) from the document tree. Perhaps the earlier include:: is not processed at all in the scope of the later child pages, leaving the attributes missing.

@bostrt
Copy link
Author

bostrt commented Aug 29, 2023

@owenh000 Thanks for the follow-up.

@bostrt
Copy link
Author

bostrt commented Sep 5, 2023

Just by chance, I found that if I only mention in the include in the top level section then multipage renders as I would expect. Internally, this may be acting the same as the workaround you already mentioned. So the following works and renders correctly no matter the placement of the include:

= My page

include::testing.adoc[]

== Page 1

{metadata_0}

{metadata_1}

== Page 2
{metadata_2}

@owenh000
Copy link
Owner

@bostrt, thanks for sharing the example.

@gabriel-rh
Copy link

It would appear that this is a specific instance of the more general #23

Here is what works and what fails for me:

FAILS - Content in preamble

= test issue #23

include::attributes.adoc[]

If this preamble is removed, the attribute below (in Chapter) will work.

== Chapter

This should be *myvalue*: {myattr}

WORKS - No content in preamble

= test issue #23

include::attributes.adoc[]

//If this preamble is removed, the attribute below (in Chapter) will work.

== Chapter

This should be *myvalue*: {myattr}

WORKS - Move attributes definitions into header

= test issue #23
include::attributes.adoc[]

If this preamble is removed, the attribute below (in Chapter) will work.

== Chapter

This should be *myvalue*: {myattr}

WORKS - Move title into preamble

include::attributes.adoc[]

= test issue #23

If this preamble is removed, the attribute below (in Chapter) will work.

== Chapter

This should be *myvalue*: {myattr}

@owenh000 owenh000 added the bug Something isn't working label Apr 3, 2024
@owenh000
Copy link
Owner

owenh000 commented Apr 3, 2024

I think this could be considered a bug in asciidoctor-multipage. It would be easier to work on with issue #46 completed.

@owenh000 owenh000 changed the title Inherting included attributes Inheriting included attributes Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants