Login  Register

Creating tables in extensions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Creating tables in extensions

lorrden
I cannot figure out how to create a table in an extension. Does anyone have any pointers for how to do this?

I want to create a block macro extension that automatically creates an Asciidoctor table in the AST, and it should work with both the html, docbook and pdf output (through Asciidoctor-pdf).

I have been able to create small text fragments and other items, but not tables.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Creating tables in extensions

mojavelinux
Administrator
The table AST really wasn't designed as a public-facing API. The best way to do it at the moment is to generate AsciiDoc, then use the parse_content method to parse it into a block. You can see that being done in this extension: https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/textql-block.rb

Cheers,

-Dan

On Fri, Apr 26, 2019 at 10:32 AM lorrden [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I cannot figure out how to create a table in an extension. Does anyone have any pointers for how to do this?

I want to create a block macro extension that automatically creates an Asciidoctor table in the AST, and it should work with both the html, docbook and pdf output (through Asciidoctor-pdf).

I have been able to create small text fragments and other items, but not tables.


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


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Creating tables in extensions

lorrden
Thanks,  that got me in the right direction, just for reference something like this will work:

class FooBarMacro < Asciidoctor::Extensions::BlockMacroProcessor
  use_dsl

  named :foobar

  def process parent, target, attrs
    tab = ['[width="15%"]',
           '|=======',
           '|1 |2 |A',
           '|3 |4 |B',
           '|5 |6 |C',
           '|=======']
    block = create_open_block parent, '', attrs
    parse_content block, tab, attrs
  end
end