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
Alternatively, 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 AngleSharp.Dom.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.

  • WithEndWordSeparators(params char[] endWordSeparators)

    Adds additional end word separator characters when limiting matches to whole words only. These additional characters are in addition to the default of splitting words at white space.

    • endWordSeparators

      Additional word separators that should be considered for the end of a word.

  • 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). By default whole words are determined by testing for white space.

    • matchOnlyWholeWord

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

  • WithQuerySelector(string querySelector)

    Allows you to specify an alternate query selector.

    • querySelector

      The query selector to use.

  • WithStartWordSeparators(params char[] startWordSeparators)

    Adds additional start word separator characters when limiting matches to whole words only. These additional characters are in addition to the default of splitting words at white space.

    • startWordSeparators

      Additional word separators that should be considered for the start of a word.

  • WithWordSeparators(params char[] wordSeparators)

    Adds additional word separator characters when limiting matches to whole words only. These additional characters are in addition to the default of splitting words at white space.

    • wordSeparators

      Additional word separators that should be considered for the start and end of a word.

GitHub