Re: Inserting toc entries from hyperlinked source code

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

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,