AutoLink Wyam.Html

Replaces occurrences of specified strings with HTML links.
This module is smart enough to only look in specified HTML elements (p by default). You can supply an alternate query selector to narrow the search scope to different container elements or to those elements that contain (or don't contain) a CSS class, etc. It also won't generate an HTML link if the replacement text is already found in another link.

Package

This module exists in the Wyam.Html package which is not part of the core distribution. Add the following preprocessor directive to your configuration file to use it:
#n Wyam.Html
Alternativly, you can add all modules at once with the following preprocessor directive:
#n Wyam.All

Usage

  • AutoLink()

    Creates the module without any initial mappings. Use AddLink(...) to add mappings with fluent methods.

  • AutoLink(ContextConfig links)

    Specifies a dictionary of link mappings given an Wyam.Common.Execution.IExecutionContext. The return value is expected to be a IDictionary<string, string>. The keys specify strings to search for in the HTML content and the values specify what should be placed in the href attribute. This uses the same link mappings for all input documents.

    • links

      A delegate that returns a dictionary of link mappings.

  • AutoLink(DocumentConfig links)

    Specifies a dictionary of link mappings given an IDocument and Wyam.Common.Execution.IExecutionContext. The return value is expected to be a IDictionary<string, string>. The keys specify strings to search for in the HTML content and the values specify what should be placed in the href attribute. This allows you to specify a different mapping for each input document.

    • links

      A delegate that returns a dictionary of link mappings.

  • AutoLink(IDictionary<string, string> links)

    Specifies a dictionary of link mappings. The keys specify strings to search for in the HTML content and the values specify what should be placed in the href attribute. This uses the same link mappings for all input documents.

    • links

      A dictionary of link mappings.

Fluent Methods

Chain these methods together after the constructor to modify behavior.

  • WithLink(string text, string link)

    Adds an additional link to the mapping. This can be used whether or not you specify a mapping in the constructor.

    • text

      The text to search for.

    • link

      The link to insert.

  • WithMatchOnlyWholeWord(bool matchOnlyWholeWord = true)

    Forces the string search to only consider whole words (it will not add a link in the middle of a word).

    • matchOnlyWholeWord

      If set to true the module will only insert links at work boundaries.

  • WithQuerySelector(string querySelector)

    Allows you to specify an alternate query selector.

    • querySelector

      The query selector to use.

GitHub