Printing the id of a block

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Printing the id of a block

Daniel K
Hi all,

we are using blocks with ids as follows:

[#blockid,role="highlightedblock"]
:myattribute: myvalue
--
Text in block

{myattribute}

--

It is possible to print out the value of a defined attribute.

Is it somehow possible to print the id of the current block itself?

The Id shall be shown in the HTML and PDF output.

For HTML, we currently using a workaround with CSS:

.highlightedblock::before {content: "[" attr(id) "]"; margin-right: 1em; font-weight: bold}

This is not a very nice solution since it does not work with the PDF output. Moreover, in HTML it is not part of the DOM tree.

Does somebody see any solution to solve this issue?

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Printing the id of a block

mojavelinux
Administrator
Daniel,

To activate attribute references inside a verbatim block, you must apply incremental subs to the block:

[subs=attributes+]

The ID of the block cannot be referenced using an attribute reference. However, you may define the ID using a document attribute, then assign it to the block ID (so the other way around)

:block-id: foobar
[id={block-id},subs=attributes+]
----
{block-id}
----

Best Regards,

-Dan

On Wed, Apr 22, 2020 at 5:46 AM Daniel K [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi all,

we are using blocks with ids as follows:

[#blockid,role="highlightedblock"]
:myattribute: myvalue
--
Text in block

{myattribute}

--

It is possible to print out the value of a defined attribute.

Is it somehow possible to print the id of the current block itself?

The Id shall be shown in the HTML and PDF output.

For HTML, we currently using a workaround with CSS:

.highlightedblock::before {content: "[" attr(id) "]"; margin-right: 1em; font-weight: bold}

This is not a very nice solution since it does not work with the PDF output. Moreover, in HTML it is not part of the DOM tree.

Does somebody see any solution to solve this issue?

Thanks!


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Printing-the-id-of-a-block-tp7943.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: Printing the id of a block

Daniel K
Hi Dan,
thanks for the information.

Would there also be a possibility to solve this issue by writing a plugin which inserts the id into the output?

Regards,

Daniel
Reply | Threaded
Open this post in threaded view
|

Re: Printing the id of a block

mojavelinux
Administrator
Absolutely. An extension can modify the document in almost any conceivable way. I would probably use a tree processor for something like this, which can visit the source blocks and manipulate the data.

Best Regards,

-Dan

On Thu, Apr 23, 2020 at 2:11 AM Daniel K [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi Dan,
thanks for the information.

Would there also be a possibility to solve this issue by writing a plugin which inserts the id into the output?

Regards,

Daniel


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Printing-the-id-of-a-block-tp7943p7948.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux