Inserting arbitrary links in TOC

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Inserting arbitrary links in TOC

aalmiray
Hi there,

How can I insert additional links in the TOC that are not related to sections?

Cheers,
Andres
Reply | Threaded
Open this post in threaded view
|

Re: Inserting arbitrary links in TOC

mojavelinux
Administrator
Andres,

This is not currently possible, short of implementing your own table of contents (i.e., outline). You can do the latter by either extending the Html5Converter class and overriding the outline method:


or implementing a custom template where the outline is emitted, for instance the document.html.slim:


We should probably have a way to "promote" an element to the TOC. The question is, which element is it? Would it be more appropriate to simply have something like a list of figures, tables, etc?

Cheers,

-Dan


On Sun, Aug 3, 2014 at 1:27 PM, aalmiray [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi there,

How can I insert additional links in the TOC that are not related to sections?

Cheers,
Andres


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Inserting-arbitrary-links-in-TOC-tp1952.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Inserting arbitrary links in TOC

daveb
In reply to this post by aalmiray
I have an extension that does just this:

# Add all the functions we have hyperlinked into the toc.
class CustomTocPostprocessor < Asciidoctor::Extensions::Postprocessor
        def process(document, output)
                $headings.each do |name, headings|
                        prefix = headings[:prefix]
                        section = %Q{<ul class="sectlevel2">\n} +
                                                headings[:functions].map {|f| %Q{<li><a href="##{prefix}_#{f}">#{f}<\/a><\/li>\n}}.join + '</ul>'

                        # Pick up the last occurrence of name so we know we have the one in the behavioural model section.
                        output = output.sub(/(.*<li><a href=".*?#{name}<\/a><\/li>)/m, '\1' + section)
                end
               
                output
        end
end


Basically I am including a lot of source code sections into the document and I want to add in the function names into the TOC.  The $headings is a hash of section names with details of the functions in each section.  The hyperlink to the action contents is formed from the section prefix (in case the same function name exists across sections) and the function name.

Dave.
Reply | Threaded
Open this post in threaded view
|

Re: Inserting arbitrary links in TOC

mojavelinux
Administrator

Nice one!

This would make a good demo for the extensions lab.

-Dan

On Sep 16, 2014 4:07 AM, "daveb [via Asciidoctor :: Discussion]" <[hidden email]> wrote:
I have an extension that does just this:

# Add all the functions we have hyperlinked into the toc.
class CustomTocPostprocessor < Asciidoctor::Extensions::Postprocessor
        def process(document, output)
                $headings.each do |name, headings|
                        prefix = headings[:prefix]
                        section = %Q{<ul class="sectlevel2">\n} +
                                                headings[:functions].map {|f| %Q{<li><a href="##{prefix}_#{f}">#{f}<\/a><\/li>\n}}.join + '</ul>'

                        # Pick up the last occurrence of name so we know we have the one in the behavioural model section.
                        output = output.sub(/(.*<li><a href=".*?#{name}<\/a><\/li>)/m, '\1' + section)
                end
               
                output
        end
end


Basically I am including a lot of source code sections into the document and I want to add in the function names into the TOC.  The $headings is a hash of section names with details of the functions in each section.  The hyperlink to the action contents is formed from the section prefix (in case the same function name exists across sections) and the function name.

Dave.



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Inserting-arbitrary-links-in-TOC-tp1952p2225.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Inserting arbitrary links in TOC

daveb
Feel free to use this as you see fit.
One part I don't like about this is using the global to pass arbitrary data into the extension, but it works and is expedient.

Dave.