Re: Custom styles support

Posted by mojavelinux on
URL: https://discuss.asciidoctor.org/Custom-styles-support-tp441p474.html

Pepijn,

Your example aligns perfectly with the BlockProcessor extension proposed in the changeset for issue #79.

The good news is, all the work of inline processing, etc you get for free. All you need to do is decorate the content with the extra text in AsciiDoc format that you need.

In your example, you'd create a custom block for the requirement style:

class RequirementBlock < BlockProcessor

  option :contexts, [:paragraph]
  option :content_model, :simple

  def process parent, reader, attributes
    reader.unshift_line "*Req {counter:requirement}*"
    Block.new parent, :quote, :content_module => @content_model, :source => reader.lines, :attributes => attributes
  end

end

That matches your effective AsciiDoc output above, and the following HTML:

<div class="blockquote">
  <blockquote><strong>Req 1</strong> AsciiDoctor shall support custom block styles.</blockquote>
</div>

If you need to render a custom template, you change the second argument to Block.new from :quote to the name of your custom template. You'd then need to provide a custom template, which you load using the :template_dirs API option or -T command option.

I'll be including a few examples in the release notes so that you can put this into practice. For sure, you're case is covered.

-Dan


On Fri, Aug 9, 2013 at 1:09 AM, pepijnve [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Initially my needs are pretty basic I think. What I want to do is mark paragraphs in the text with a custom style and get them rendered kind of like admonition blocks are rendered.

To be more concrete:

[requirement]
AsciiDoctor shall support custom block styles

should get turned into (for instance)
________________________
*Req {counter:requirement}* AsciiDoctor shall support custom block styles
________________________

In other words, I would like to be able to transform the text from the source document and add autogenerated text to it. The output of the filter in this case is still in asciidoc syntax so it should still be processed for substitutions (or there should be a way to trigger processing on the text via the api).


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



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