mehdown 2.56.0 → 2.57.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/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.57.0] - 2024-12-04
8
+ ### Added
9
+ - Added support for amazon.com affiliate links
10
+
7
11
  ## [2.56.0] - 2024-11-26
8
12
  ### Added
9
13
  - Added support for <video> tag rendering for .mp4 and .webm links
package/lib/index.js CHANGED
@@ -706,6 +706,7 @@ exports.render = function(markdown, options, callback) {
706
706
  md.linkify.tlds('horse', true);
707
707
  md.linkify.tlds('deals', true);
708
708
 
709
+ md.use(require('./plugins/amazon'));
709
710
  md.use(require('./plugins/anchors'), { suffix: options.id });
710
711
  md.use(require('./plugins/appleMusic'));
711
712
  md.use(require('./plugins/audio'));
@@ -786,6 +787,26 @@ exports.render = function(markdown, options, callback) {
786
787
  }, function() {
787
788
  callback();
788
789
  });
790
+ },
791
+ // https://github.com/markdown-it/markdown-it/issues/1031
792
+ function _urlEncodeFix(callback) {
793
+ const aElements = exports.html.getElementsByTagName(html, 'a');
794
+
795
+ if (!aElements?.length) {
796
+ return callback();
797
+ }
798
+
799
+ aElements.forEach(aElement => {
800
+ const href = exports.html.getAttributeValue(aElement, 'href');
801
+
802
+ if (!href?.includes('&amp;')) {
803
+ return;
804
+ }
805
+
806
+ html = html.replaceAll(`href="${href}"`, `href="${href.replaceAll('&amp;', '&')}"`);
807
+ });
808
+
809
+ return callback();
789
810
  }
790
811
  ], function(err) {
791
812
  if (err) {
@@ -0,0 +1,29 @@
1
+ const regExp = /https?:\/\/(?:[a-z0-9-]+\.)?amazon\.com(?:\/[^\s]*)?(?=\s|$)/i;
2
+
3
+ module.exports = function(md) {
4
+ const defaultRender = md.renderer.rules.link_open || function(tokens, idx, options, env, self) {
5
+ return self.renderToken(tokens, idx, options);
6
+ };
7
+
8
+ md.renderer.rules.link_open = function(tokens, idx, options, env, self) {
9
+ const openToken = tokens[idx];
10
+ const hrefIndex = openToken.attrIndex('href');
11
+
12
+ // Ensure we have an "href" attribute
13
+ if (hrefIndex !== -1) {
14
+ const href = openToken.attrs[hrefIndex][1];
15
+
16
+ // Ensure we have an "href" attribute value that matches the Amazon URL pattern
17
+ if (href && regExp.test(href)) {
18
+ const url = new URL(href);
19
+
20
+ if (!url.searchParams.has('tag')) {
21
+ url.searchParams.set('tag', 'mehdown-20');
22
+ openToken.attrs[hrefIndex][1] = url.toString();
23
+ }
24
+ }
25
+ }
26
+
27
+ return defaultRender(tokens, idx, options, env, self);
28
+ };
29
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "async": "~3.2.0",
3
+ "async": "~3.2.6",
4
4
  "emoji-toolkit": "~6.6.0",
5
5
  "flip": "~1.0.0",
6
6
  "lolspeak": "~1.4.0",
@@ -10,7 +10,7 @@
10
10
  "natural": "~5.2.4",
11
11
  "probe-image-size": "~7.2.0",
12
12
  "rel-to-abs": "~0.1.0",
13
- "request": "~2.88.0",
13
+ "request": "~2.88.2",
14
14
  "roll": "~1.3.1",
15
15
  "shell-quote": "~1.8.0",
16
16
  "slug": "~9.0.0",
@@ -33,5 +33,5 @@
33
33
  "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
34
34
  "test": "mocha --reporter spec test/*"
35
35
  },
36
- "version": "2.56.0"
36
+ "version": "2.57.0"
37
37
  }