How to include a javascript in Asciidoc?
Asked Answered
T

2

16

I'm using asciidoctor-maven-plugin to convert .adoc files to html file... Would want to include a link to javascript in the generated html file... Basically would like to see something like below in the html file that is generated from the .adoc file

<script src="custom.js"></script>

Tried setting attributes like linkcss scriptsdir etc..but of no luck...

Any help?

One way is like in http://mrhaki.blogspot.ie/2014/06/awesome-asciidoc-include-raw-html.html

But then have to add it in every .adoc file...is there a way to get it automatically added just like the CSS (using stylesheet)

Trident answered 20/10, 2014 at 14:11 Comment(3)
This? asciidoctor.org/docs/install-and-use-asciidoctorjsAsta
@Diodeus That's not what the question's asking. OP, have you tried just escaping the <>? See here for info: https://mcmap.net/q/345774/-escape-tags-in-htmlFivefinger
I've edited your question to make code visible. Next time don't forget to check what you're about to post in the bottom preview panel ;-)Foretooth
G
14

You can use the passthrough block for that using ++++:

++++
<p>
Content in a passthrough block is passed to the output unprocessed.
That means you can include raw HTML, like this embedded Gist:
</p>

<script src="http://gist.github.com/mojavelinux/5333524.js">
</script>
++++

Source: http://asciidoctor.org/docs/asciidoc-syntax-quick-reference/#more-delimited-blocks

Gogol answered 5/4, 2015 at 11:46 Comment(2)
Though it works, there's a limitation that you can't pass any values inside this block.Hayott
What does this do for PDF output? Ignore it I guess?Hood
A
13

Use docinfo files, see the documentation for more detail.

You create docinfo files by adding another file named <doc_file_name>-docinfo.html for HTML generation or <doc_file_name>-docinfo.xml for docbook generation. The contents of the docinfo file are copied into the generated output, in the head section for html. If you want to add things to the bottom of the document there are footer docinfo files for that. It follows the same as a normal docinfo but the file name is <doc_file_name>-docinfo-footer.html or <doc_file_name>-docinfo-footer.xml

Happy docing :) Let me, or preferably the list know of any other maven issues you find.

Accede answered 21/10, 2014 at 3:32 Comment(1)
And don't forget to set the :docinfo: attribute in your adoc, to the corresponding value! (also explained in the docs linked by @LightGuard)Anthropomorphize

© 2022 - 2024 — McMap. All rights reserved.