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>+++ ?

1

2 Answers 2

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").

3
  • 1
    Thanks you for your help. I am just wondering, is it somehow possible to make only <div class="userinput"> whithout the "paragraph" in it?
    – trabant
    Mar 17, 2016 at 8:59
  • Not without creating your own output template.
    – LightGuard
    Mar 17, 2016 at 17:22
  • Is there something like this available for asciidoc?
    – vfclists
    Jun 26, 2017 at 13:55
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.