Re: Add a javascript to the page generated (guard)
Posted by
mojavelinux on
URL: https://discuss.asciidoctor.org/Add-a-javascript-to-the-page-generated-guard-tp685p716.html
Charles,
It doesn't work when you use the API because you still need to set the safe mode option.
guard 'shell' do
watch(/^*\.adoc$/) {|m|
Asciidoctor.render_file(m[0], {
:in_place => true,
:safe => :unsafe,
:attributes => {
'backend' => 'html5',
'linkcss' => '',
'docinfo' => ''
}
})
}
end
Btw, you can also set the backend using an option:
guard 'shell' do
watch(/^*\.adoc$/) {|m|
Asciidoctor.render_file(m[0], {
:in_place => true,
:safe => :unsafe,
:backend => :html5,
:attributes => {
'linkcss' => '',
'docinfo' => ''
}
})
}
end
Though html5 is the default, so you really don't need to set it.
You can also set the attributes using a string (or string-based array syntax) similar to how they are set on the commandline:
guard 'shell' do
watch(/^*\.adoc$/) {|m|
Asciidoctor.render_file(m[0], {
:in_place => true,
:safe => :unsafe,
:backend => :html5,
:attributes => 'linkcss docinfo'
})
}
end
Hopefully that should do the trick.
-Dan