@bartificer/linkify 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bartificer/linkify",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "An module for converting URLs into pretty links in any format.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -2,6 +2,7 @@ import { PageData } from './PageData.class.mjs';
2
2
  import { LinkData } from './LinkData.class.mjs';
3
3
  import { LinkTemplate } from './LinkTemplate.class.mjs';
4
4
  import * as utilities from "./utilities.mjs";
5
+ import * as defaults from "./defaults.mjs";
5
6
 
6
7
  import fetch from 'node-fetch';
7
8
  import * as cheerio from 'cheerio';
@@ -42,21 +43,18 @@ export class Linkifier {
42
43
  this._utilities = utilities;
43
44
 
44
45
  //
45
- // === Create and register the default templates ===
46
+ // -- Create and register the default templates --
46
47
  //
47
- // TO DO migrate these to a separate file
48
- this.registerTemplate(
49
- 'html',
50
- new LinkTemplate('<a href="{{{url}}}" title="{{description}}">{{text}}</a>')
51
- );
52
- this.registerTemplate(
53
- 'htmlNewTab',
54
- new LinkTemplate('<a href="{{{url}}}" title="{{description}}" target="_blank" rel="noopener">{{text}}</a>')
55
- );
56
- this.registerTemplate(
57
- 'markdown',
58
- new LinkTemplate('[{{{text}}}]({{{url}}})')
59
- );
48
+ for (const [name, template] of Object.entries(defaults.linkTemplates)) {
49
+ this.registerTemplate(name, template);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * @type {string[]} A list of the names of the registered link templates.
55
+ */
56
+ get templateNames() {
57
+ return Object.keys(this._linkTemplates);
60
58
  }
61
59
 
62
60
  /**
@@ -0,0 +1,10 @@
1
+ import { LinkTemplate } from './LinkTemplate.class.mjs';
2
+
3
+ /**
4
+ * @type {Object.<string, LinkTemplate>} A collection of named link templates.
5
+ */
6
+ export const linkTemplates = {
7
+ html: new LinkTemplate('<a href="{{{url}}}" title="{{description}}">{{text}}</a>'),
8
+ htmlNewTab: new LinkTemplate('<a href="{{{url}}}" title="{{description}}" target="_blank" rel="noopener">{{text}}</a>'),
9
+ markdown: new LinkTemplate('[{{{text}}}]({{{url}}})')
10
+ };