toc

package
v0.26.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 4 Imported by: 7

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateAnchors added in v0.14.0

func GenerateAnchors(root *web.Element, names ...string)

func GenerateIDs

func GenerateIDs(root *web.Element, names ...string)
Example
a := Article(
	Section(
		H2(Id("current"), "Current car"),
		H2("My first car"),
		H2("My first car"),
		H2("My first car"),
		H3("Broke down"),
	),
)
GenerateIDs(a, "h2")
a.WriteTo(os.Stdout)
Output:

<article>
<section>
<h2 id="current">Current car</h2>
<h2 id="myfirstcar">My first car</h2>
<h2 id="myfirstcar1">My first car</h2>
<h2 id="myfirstcar2">My first car</h2>
<h3>Broke down</h3>
</section>
</article>

func MakeTOC added in v0.13.0

func MakeTOC(dest, root *web.Element, names ...string) *web.Element

MakeTOC generates ids for all named elements and generates a TOC into the destination element returning the created UL element.

Example
nav := Nav()
a := Article(
	H1("Programming"),
	nav,
	H2("Design"),
	H3("Diagrams"),

	Section(
		H2(Id("myid"), "Test"),
		H3("Unit"),
		H3("Integration"),
	),
)
MakeTOC(nav, a, "h2")
nav.WriteTo(os.Stdout)
Output:

<nav><ul>
<li class="h2"><a href="#design">Design</a></li>
<li class="h2"><a href="#myid">Test</a></li>
</ul>
</nav>

func ParseTOC

func ParseTOC(root *web.Element, names ...string) *web.Element

ParseTOC returns ul > li of all named elements.

Example
a := Article(
	H1("Programming"),
	H2("Design"),
	H2("Design"),
	H3("Diagrams"),

	Section(
		H2(Id("myid"), "Test"),
		H3("Unit"),
		H3("Integration"),
	),
)
toc := ParseTOC(a, "h2")
toc.WriteTo(os.Stdout)
Output:

<ul>
<li class="h2"><a href="#design">Design</a></li>
<li class="h2"><a href="#design1">Design</a></li>
<li class="h2"><a href="#myid">Test</a></li>
</ul>

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL