How can I make custom class HTML divisions using AsciiDoctor?
Asked Answered
G

2

11

I am beginning with AsciiDoctor and I want to output HTML. I've been trying to figure out how to create custom class in divisions, I searched google, manuals etc. and couldn't find a solution. What I want to do is simply write something like this:

Type the word [userinput]#asciidoc# into the search bar.

Which generates HTML

<span class="userinput">asciidoc</span>

but I want to have div tags instead of span. Is there any way to do it or should I just use something like +++<div class="userinput">asciidoc</span>+++ ?

Galilean answered 16/3, 2016 at 18:21 Comment(1)
S
7

I think what you need is called "role" in Asciidoctor.

This example:

This is some text.

[.userinput]
Type the word asciidoc into the search bar.

This is some text.

Produces:

<div class="paragraph">
<p>This is some text.</p>
</div>
<div class="paragraph userinput">
<p>Type the word asciidoc into the search bar.</p>
</div>
<div class="paragraph">
<p>This is some text.</p>
</div>

You have now a css selector div.userinput for the concerned div.

See 13.5. Setting attributes on an element in the Asciidoctor User Manual (you can also search for "role").

Saprolite answered 17/3, 2016 at 5:40 Comment(3)
Thanks you for your help. I am just wondering, is it somehow possible to make only <div class="userinput"> whithout the "paragraph" in it?Galilean
Not without creating your own output template.Autocade
Is there something like this available for asciidoc?Narcose
S
6

You may want to use an open block for that purpose:

Type the following commands:

[.userinput]
--
command1

command1
--

Producing:

<div class="paragraph">
  <p>Type the following commands:</p>
</div>
<div class="openblock userinput">
  <div class="content">
    <div class="paragraph">
      <p>command1</p>
    </div>
    <div class="paragraph">
      <p>command1</p>
    </div>
  </div>
</div>

The advantage is it can wrap any other block and is not limited to only one paragraph like the other answer.

For slightly different use cases, you may also consider defining a custom style.

Secession answered 9/3, 2018 at 23:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.