cynepnaxa
cynepnaxa

Reputation: 1054

How to dynamically hide asciidoc element

I use org.asciidoctor.convert plugin for gradle to generate API documentation for my team. I include files:

include::{snippets}/index/curl-request.adoc[] 

and want to place it's content into spoiler or anything like that. Is there any way to somehow hide dynamicaly asciidoc elements? I try to use

pass:[<details open>  
include::{snippets}/index/curl-request.adoc[]
</details>]

but it is not processed include inside it. Any ideas will be higly appreciated. Without hiding snippets my documentation have almost unlimited scrol :). If no such way with ascii doc, suggestions of other documentation formats, where i can include files content and place it into the spoiler is also appreciated.

Upvotes: 12

Views: 8826

Answers (3)

pme
pme

Reputation: 14803

As this was so helpful for me - I added here the solution from Robin's comment.

No CSS and Javascript needed!

Here is an example:

+++ <details><summary> +++
Check `reference.conf`:
+++ </summary><div> +++
----
play {
  http {
    secret.key = asdf
    secret.key = ${?SECRET_KEY}
    ...
  }
  ...
}
----
+++ </div></details> +++

This creates a collapsed element:

enter image description here

..and this expanded image:

enter image description here

Update

As Foad's answer looks more elegant, I tried his proposed solution for a ReDoc Markup with no success.

Upvotes: 13

Foad S. Farimani
Foad S. Farimani

Reputation: 14008

As Guillaume Grossetie has mentioned here

Using passthrough to include raw HTML is not recommended because now your document is tightly coupled with the output.

and it is deprecated. The new syntax for collapsible/foldable sections is

.some description
[%collapsible]
====
this
is
going
to be
folded
====

Upvotes: 14

snorbi
snorbi

Reputation: 2890

This is a late answer but maybe it will help you/others. The following asciidoc features are the key for implementing dynamic showing/hiding of blocks:

If your output is only HTML then you can embed any HTML in the document using

++++ any HTML contents ++++

This includes

  • <style> tags containing custom CSS classes
  • custom HTML tags for show/hide functionality like <input type="checkbox" />
  • <script> tags containing Javascript code to hide/show some blocks, e.g. by adding event listeners to checkboxes.

As @LightGuard has already mentioned, role attributes are converted to CSS class references. E.g.

[source,role="someCssClass"]
----
...
----

is converted to something like

<div class="someCssClass">
</div>

So you can reference this CSS class from Javascript code and implement show/hide by modifying the display CSS attribute.

For a simple example implementation see https://raw.githubusercontent.com/NorbertSandor/jsinterop.xyz/master/jsinterop-project/jsinterop-website/src/main/asciidoc/index.asciidoc (near the top of the file).

Upvotes: 4

Related Questions