Re: Inserting toc entries from hyperlinked source code

Posted by mojavelinux on
URL: https://discuss.asciidoctor.org/Inserting-toc-entries-from-hyperlinked-source-code-tp668p698.html

Dave,

Aha! There's a very important piece of information you need to know, which we'll be sure to call attention to in the user guide. When you switch from the CLI (asciidoctor) to the API, the default safe mode switches from the lowest (unsafe) to the highest (secure). We kept the CLI consistent with AsciiDoc Python, but the API default had to change to accommodate requirements for GitHub deployment.

To restore all the missing functionality, add the following option to the Asciidoctor#render_file invocation:

:safe => :unsafe

or

:safe => :safe

That should solve #1, #2 and #3.

To help highlight this change, we'll definitely add the API equivalent of what a given command line invocation does. Good thinking! 

The main (and really only) difference between the unsafe and safe modes is that in unsafe mode, Asciidoctor can include files from anywhere, whereas in safe mode it can only include files starting from the working directory.

Btw, in AsciiDoc, the attribute value empty string is the same as a true value. Internally, Asciidoctor only looks to see if the key is set in the case of a boolean attributes.

-Dan


On Thu, Oct 3, 2013 at 4:42 AM, daveb [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Thanks for the input Dan.  I will try going down the extension route.

My first stab is to replicate the command line functionality I am currently using, but I have run into 3 problems.
1.  The default style sheet isn't being copied into my output.html file.
2.  The include::{build_dir}/interfaces.adoc[] line is being ignored and only a hyperlink to the include file is being inserted into the output html file.
3.  The syntax highlighting is being ignored and nothing is being inserted into the output html file.
               [source, c]
               ----
               include::./urb_update.cpp[]
               ----

My command line (in rake) is:

sh " asciidoctor -d book -n -a data-uri -a toc2 -a toclevels=4 -a source-highlighter=coderay -a build_dir=#{UNIT_BUILD_DIR} #{input_file}"

and my asciidoctor runner is:

require 'asciidoctor'

def asciidoctor_runner (file, attributes = {})
       
        attributes.merge!( 'doctype'            => 'book',
                                                'source-highlighter' => 'coderay',
                                                'data-uri'            => true,
                                                'toc2'                  => true,  
                                                'toclevels'          => 4,
                                                'numbered'       => '',
                                                'linkcss'  => true
                                        )

       
        Asciidoctor.render_file(file, :in_place => true, :backend => 'html', :attributes => attributes)
end


and I call this from my rake task:

asciidoctor_runner(input_file, 'build_dir' => UNIT_BUILD_DIR)


No errors are printed out by asciidoctor.

I think the section in the docs that talks about the API could be expanded to say if this is your command line invocation then this is the equivalent API invocation.

Dave,


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Inserting-toc-entries-from-hyperlinked-source-code-tp668p681.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | http://google.com/profiles/dan.j.allen