New-PageHeadingNavigation

Generate navigation specifications for specified headings found in an HTML fragment.

Syntax

 New-PageHeadingNavigation [-HTMLfragment] <String> [-NavTemplate] <Object> [-HeadingLevels] <String>  [<CommonParameters>] 

Description

Generates a link specification for each heading in an HTML fragment which

The link specifications have the format required by ConvertTo-NavigationItem to generate navigation bar items.

Parameters

-HTMLfragment <String>

HTML fragment to scan for headings.


Parameter Property Value
Required? true
Position? 1
Default value ``
Accept pipeline input? false
Accept wildcard characters? false

An optional dictionary of the named HTML template needed to add a heading link to the navigation bar.

Type Key HTML Template
Heading link template "navheading"
<span class='navitem{{level}}'>{{navtext}}</span>"

The HTML template above is the value defined in Build.json. That value is used if the given dictionary does not define the "navheading" mapping or if no dictionary is given at all. Additional mappings contained in the dictionary are ignored.

For more customization options see Static Site Project Customization.

The css styles used in the template is defined in md-styles.css.

Following placeholders in the HTML template are recognized.

Placeholder Description
{{level}} heading level.
{{navtext}} heading text

During the build process the placeholders are replaced with content taken from the NavSpec parameter.


Parameter Property Value
Required? false
Position? 2
Default value $SCRIPT:defaultNavTemplate
Accept pipeline input? false
Accept wildcard characters? false

-HeadingLevels <String>

A string of numbers denoting the levels of the headings to add to the navigation bar. By default the headings at level 1,2 and 3 are added to the Navigation bar. If headings should not be automatically added to the navigation bar, use the empty string '' for this parameter. If omitted, the default configuration defined by option "capture_page_headings" in Build.json is used.


Parameter Property Value
Required? false
Position? 3
Default value 123
Accept pipeline input? false
Accept wildcard characters? false

Inputs

None. This function does not read from a pipe.

Outputs

HTML elements representing navigation links to headings on the input HTML fragment for use in the navigation bar of sites created by New-StaticHTMLSiteProject.

Notes

This function is typically used in the build script Build.ps1 to define the contents of the navigation bar (placeholder {{nav}}).

Examples

EXAMPLE 1

New-PageHeadingNavigation $fragment -HeadingLevels '234'

Create an HTML element for navigation to page headings <h2>, <h3>, <h4>. All other headings are ignored. $fragment is a HTML framgment defined as:

$fragment = '<h2 id="bob">Hello World</h2>'

Output:

<button class="navitem">
   <a href="#bob"><span class="navitem2">Hello World</span></a>
</button>

Note that the heading level has been added to the css class.

EXAMPLE 2

Hello World</h2>' -NavTemplate $custom

Create an HTML element for navigation to an heading using the custom template $custom.

    $custom = @{ navheading = '<span class="li-item{{level}}">{{navtext}}</span>'}

Output:

<button class="navitem">
    <a href="#bob"><span class="li-item2">Hello World</span></a>
</button>

Note that the heading level is used as a postfix for the css class.

Related Links


Module: MarkDownToHTML; Version: 2.4.0; (c) 2018-2021 WetHat Lab. All rights reserved.