LinkTemplate

link-template. LinkTemplate

A class representing the templates used to render link data objects as actual links.

Constructor

new LinkTemplate(templateString, filtersopt, fieldExtractoropt)

Source:
See:
Example

Example of defining a template with filters

let template = new LinkTemplate(
    '<a href="{{{url}}}">{{{text}}}</a>',
    [
        ['url', linkify.util.stripUTMParameters],
        ['text', linkify.util.regulariseWhitespace]
    ]
);
Parameters:
Name Type Attributes Default Description
templateString string

A Moustache template string.

filters Array.<templateFieldFilterTuple> <optional>
[]

an optional set of filter functions to apply to some or all template fields.

fieldExtractor templateFieldExtractorFunction <optional>

an optional function to extract additional fields from a web page DOM object, making the extracted fields available for use in the template under the extraFields key.

Members

(nullable) fieldExtractor :templateFieldExtractorFunction

Description:
  • The optional extra fields extractor function for this template. If present, this function will be called with the DOM data for a web page when the page data object is being extracted. These fields will be passed through to the link data object, and be avaialable for use within the template as extraFields.fieldName.

    For this process to work, the field extractor function must return an object containing key-value pairs, where the keys are the field names to be used in the template, and the values are strings.

Source:

The optional extra fields extractor function for this template. If present, this function will be called with the DOM data for a web page when the page data object is being extracted. These fields will be passed through to the link data object, and be avaialable for use within the template as extraFields.fieldName.

For this process to work, the field extractor function must return an object containing key-value pairs, where the keys are the field names to be used in the template, and the values are strings.

Type:
  • templateFieldExtractorFunction

(readonly) filterTuples :Array.<templateFieldFilterTuple>

Description:
  • All field filters the template applies as tuples, the first value being the field the filter applies to, the second the filter itself.

Source:

All field filters the template applies as tuples, the first value being the field the filter applies to, the second the filter itself.

Type:

(readonly) filters :Object.<string, Array.<templateFieldFilterFunction>>

Description:
  • All field filters, indexed by the fileld they apply to.

Source:

All field filters, indexed by the fileld they apply to.

Type:

(readonly) hasExtraFields :boolean

Description:
  • Whether or not this template supports extra fields.

Source:

Whether or not this template supports extra fields.

Type:
  • boolean

hasFilters :boolean

Description:
  • Whether or not the template applies any field filters.

Source:

Whether or not the template applies any field filters.

Type:
  • boolean

(readonly) numFilters :number

Description:
  • The number of field filters the template applies.

Source:

The number of field filters the template applies.

Type:
  • number

templateString :string

Description:
  • The Mustache template string. Will be coerced to a string with String(templateString).

Source:

The Mustache template string. Will be coerced to a string with String(templateString).

Type:
  • string

Methods

addFilter(fieldName, filterFn) → {module:link-template.LinkTemplate}

Description:
  • Add a filter to be applied to one or all fields.

    If an invalid args are passed, the function does not save the filter or throw an error, but it does log a warning.

Source:
Parameters:
Name Type Description
fieldName "all" | "url" | "text" | "description"
filterFn templateFieldFilterFunction

the filter function.

Returns:

Returns a reference to self to facilitate function chaining.

Type
module:link-template.LinkTemplate

filtersFor(fieldName) → {Array.<templateFieldFilterFunction>}

Description:
  • Get the filter functions that should be applied to any given field.

Source:
Parameters:
Name Type Description
fieldName "all" | "url" | "text" | "description"
Returns:

returns an array of callbacks, which may be empty. An empty array is also returned if an invalid field name is passed.

Type
Array.<templateFieldFilterFunction>