@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/README.md +70 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/Linkifier.class.mjs +12 -14
- package/src/defaults.mjs +10 -0
package/package.json
CHANGED
package/src/Linkifier.class.mjs
CHANGED
|
@@ -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
|
-
//
|
|
46
|
+
// -- Create and register the default templates --
|
|
46
47
|
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.
|
|
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
|
/**
|
package/src/defaults.mjs
ADDED
|
@@ -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
|
+
};
|