Re: Create extension to embed source code
Posted by
LightGuardjp on
URL: https://discuss.asciidoctor.org/Create-extension-to-embed-source-code-tp3645p3646.html
I've not written one in the gradle script, but what you'll want is certainly a block and not inline. Think of a block as an HTML div and inline like a span. If what you're creating for the asciidoc output (not final output) is a child of something else it's an inline macro. If it lives on its own then it's a block macro.
On Monday, August 10, 2015, bodiam [via Asciidoctor :: Discussion] <
[hidden email]> wrote:
Hi all,
I'm trying to write a small extension, but even after reading quite some documentation, I still have no idea what the difference is between createInline and createBlock, and I'm not sure if I'm doing things right here.
The 'problem' I have is that I have a lot of code like this:
[source, scala]
.Sample1.scala
----
include::{rootdir}/src/main/scala/samples/flatmap/Sample1.scala[tags=helloMethod]
----
That's 5 lines every time, plus there's duplication. So, I'd like to get of rid of that, and I was hoping I could do the same thing with creating a macro or extension like this:
source::flatmap/Sample1.scala[tags=helloMethod]
And be done. But I have no idea how write the code for this. I currently have the following code:
// Here we can add the code for extensions we write.
extensions {
// Implementation for inline macro to replace
// source:flatmap/Sample1[tag=helloMethod] with a link to the issue.
inlinemacro (name: "source") { parent, target, attributes ->
options = [
"type": ":link",
"target": "http://issue-server/browse/${target}".toString()
]
// Create the link to the issue.
createBlock(parent, "anchor", target, attributes, options).render()
}
}
but that doesn't do anything yet, it's based on:
http://blog.jdriven.com/2015/03/awesome-asciidoctor-use-inline-extension-dsl-with-gradle/
and
https://github.com/asciidoctor/asciidoctorj-groovy-dsl
Can anyone help me out, or point me in the right direction? Thanks!
Erik
To start a new topic under Asciidoctor :: Discussion, email <a href="javascript:_e(%7B%7D,'cvml','ml-node%2Bs49171n1h37@n6.nabble.com');" target="_blank">ml-node+s49171n1h37@...
To unsubscribe from Asciidoctor :: Discussion,
click here.
NAML
--
Sent from Gmail Mobile