Help creating extension

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

Help creating extension

tim.movin
Hi! I'm trying to write an extension where different blocks of code are put under a tab for their specific language. I'm not very experienced with Asciidoctor or Ruby, but this functionality is a requirement for the use I need it for, so that's why I'm immediately diving into writing an extension.

The following input (syntax can change to suit asciidoctor better)...

[multicode]
--
[code:C code]
[source,c]
----
void somecrazyCcode() { }
----
[code:D code]
[source,d]
----
void somecrazyDcode() { }
----
--

should roughly produce this output:
<div class="tabbedcode">
<div class="listingblock" data-code="C code">
<div class="content">
<pre class="highlight"><code class="language-c" data-lang="c">void somecrazyCcode() { }</code></pre>
</div>
</div>
<div class="listingblock" data-code="D code">
<div class="content">
<pre class="highlight"><code class="language-d" data-lang="d">void somecrazyDcode() { }</code></pre>
</div>
</div>
</div>
The rest of the tabs stuff I'll be handling with javascript. The problem is I do now know, once creating a block with create_block, how you add a class to it. I also do not know how to add an attribute to the out.

The code I've got so far:
require 'asciidoctor/extensions'

include Asciidoctor


class CustomAdmonitionBlock < Extensions::BlockProcessor
  use_dsl
  named :multicode
  on_contexts :open

  def process parent, reader, attrs

    create_block parent, :open, reader.lines, attrs, content_model: :compound
    
  end
end

class CustomAdmonitionBlockDocinfo < Extensions::DocinfoProcessor
  use_dsl

  def process doc
    '<style></style>'
  end
end

Reply | Threaded
Open this post in threaded view
|

Re: Help creating extension

mojavelinux
Administrator
once creating a block with create_block, how you add a class to it.

You set the role attribute. You can use the add_role method to do this.

Btw, there is an extension for tabs already, though it's written in Java.


You can perhaps use that for ideas and guidance.

Cheers,

-Dan

On Thu, Oct 12, 2017 at 8:40 AM, tim.movin [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi! I'm trying to write an extension where different blocks of code are put under a tab for their specific language. I'm not very experienced with Asciidoctor or Ruby, but this functionality is a requirement for the use I need it for, so that's why I'm immediately diving into writing an extension.

The following input (syntax can change to suit asciidoctor better)...

[multicode]
--
[code:C code]
[source,c]
----
void somecrazyCcode() { }
----
[code:D code]
[source,d]
----
void somecrazyDcode() { }
----
--

should roughly produce this output:
<div class="tabbedcode">
<div class="listingblock" data-code="C code">
<div class="content">
<pre class="highlight"><code class="language-c" data-lang="c">void somecrazyCcode() { }</code></pre>
</div>
</div>
<div class="listingblock" data-code="D code">
<div class="content">
<pre class="highlight"><code class="language-d" data-lang="d">void somecrazyDcode() { }</code></pre>
</div>
</div>
</div>
The rest of the tabs stuff I'll be handling with javascript. The problem is I do now know, once creating a block with create_block, how you add a class to it. I also do not know how to add an attribute to the out.

The code I've got so far:
require 'asciidoctor/extensions'

include Asciidoctor


class CustomAdmonitionBlock < Extensions::BlockProcessor
  use_dsl
  named :multicode
  on_contexts :open

  def process parent, reader, attrs

    create_block parent, :open, reader.lines, attrs, content_model: :compound
    
  end
end

class CustomAdmonitionBlockDocinfo < Extensions::DocinfoProcessor
  use_dsl

  def process doc
    '<style></style>'
  end
end




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Help-creating-extension-tp5965.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