Add new attribute to the html p tag

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

Add new attribute to the html p tag

vicziani
The AsciiDoctor generates a p tag around the paragraphs. I need to generate a html file with additional non-html attributes in some paragraph, for example:

<p foo="bar">
Lorem ipsum...
</p>

How could I indicate it in the AsciiDoc source? With a style? Or with a macro?

Which extension point should I use? Block processor can't modify the outer p tag. Only the Postprocessor can access the generated output, but how could I instruct it to add this new attribute for a specific paragraph?

Thanks,
István
Reply | Threaded
Open this post in threaded view
|

Re: Add new attribute to the html p tag

mojavelinux
Administrator
István,

This is the ideal case for using a custom template for the paragraph node. The template is loaded by the template converter. 

All generated output in Asciidoctor is customizable. The extension point for this customization is the Converter. Since creating a custom converter from scratch is laborious, the built-in template converter provides a way for you to modify the output per node à la carte. You simply supply a template that maps to a given node, in this case the paragraph node, and Asciidoctor will use that template instead of the built-in handler.

1. Begin by creating a folder to hold the templates, let's call it "templates".

2. Next, create a file named "paragraph.html.slim" in that folder. (I strongly recommend using the Slim template engine. See http://slim-lang.com/)

3. Populate the "paragraph.html.slim" file with your own template logic. Here's a simple example:

.paragraph
  p foo='bar' =content

The context is a node, in this case a Block node. See http://www.rubydoc.info/gems/asciidoctor/Asciidoctor/Block

TIP: To make the output simpler, you can put a helpers.rb file in the same directory and define functions to simplify repeating elements that appear in various templates. Here's an example: https://github.com/asciidoctor/asciidoctor-backends/blob/master/slim/html5/helpers.rb

4. Load the templates using the -T flag from the CLI:

$ asciidoctor -T path/to/templates file.adoc

When invoking Asciidoctor via the API, you load the templates by supplying the :templates option.

There is an open issue to document this feature. See https://github.com/asciidoctor/asciidoctor.org/issues/80

-Dan

On Wed, Nov 25, 2015 at 5:44 PM, vicziani [via Asciidoctor :: Discussion] <[hidden email]> wrote:
The AsciiDoctor generates a p tag around the paragraphs. I need to generate a html file with additional non-html attributes in some paragraph, for example:

<p foo="bar">
Lorem ipsum...
</p>

How could I indicate it in the AsciiDoc source? With a style? Or with a macro?

Which extension point should I use? Block processor can't modify the outer p tag. Only the Postprocessor can access the generated output, but how could I instruct it to add this new attribute for a specific paragraph?

Thanks,
István


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Add-new-attribute-to-the-html-p-tag-tp3976.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen