mehdown 2.56.0 → 2.58.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,14 @@ 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.58.0] - 2024-02-13
8
+ ### Added
9
+ - Added support for collapsibles via the HTML <details> and <summary> elements
10
+
11
+ ## [2.57.0] - 2024-12-04
12
+ ### Added
13
+ - Added support for amazon.com affiliate links
14
+
7
15
  ## [2.56.0] - 2024-11-26
8
16
  ### Added
9
17
  - Added support for <video> tag rendering for .mp4 and .webm links
package/lib/index.js CHANGED
@@ -706,6 +706,8 @@ 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('markdown-it-collapsible'));
710
+ md.use(require('./plugins/amazon'));
709
711
  md.use(require('./plugins/anchors'), { suffix: options.id });
710
712
  md.use(require('./plugins/appleMusic'));
711
713
  md.use(require('./plugins/audio'));
@@ -786,6 +788,26 @@ exports.render = function(markdown, options, callback) {
786
788
  }, function() {
787
789
  callback();
788
790
  });
791
+ },
792
+ // https://github.com/markdown-it/markdown-it/issues/1031
793
+ function _urlEncodeFix(callback) {
794
+ const aElements = exports.html.getElementsByTagName(html, 'a');
795
+
796
+ if (!aElements?.length) {
797
+ return callback();
798
+ }
799
+
800
+ aElements.forEach(aElement => {
801
+ const href = exports.html.getAttributeValue(aElement, 'href');
802
+
803
+ if (!href?.includes('&amp;')) {
804
+ return;
805
+ }
806
+
807
+ html = html.replaceAll(`href="${href}"`, `href="${href.replaceAll('&amp;', '&')}"`);
808
+ });
809
+
810
+ return callback();
789
811
  }
790
812
  ], function(err) {
791
813
  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
+ };
@@ -1,25 +1,25 @@
1
1
  module.exports = function(md, args) {
2
- var defaultRender = md.renderer.rules.link_open || function(tokens, idx, options, env, self) {
2
+ const defaultRender = md.renderer.rules.link_open || function(tokens, idx, options, env, self) {
3
3
  return self.renderToken(tokens, idx, options);
4
4
  };
5
5
 
6
6
  md.renderer.rules.link_open = function(tokens, idx, options, env, self) {
7
- var baseUrl = (args && args.baseUrl) || (options && options.baseUrl);
7
+ const baseUrl = args?.baseUrl || options?.baseUrl;
8
8
 
9
9
  if (baseUrl) {
10
- var token = tokens[idx];
11
- var hrefIndex = token.attrIndex('href');
10
+ const token = tokens[idx];
11
+ const hrefIndex = token.attrIndex('href');
12
12
 
13
13
  if (hrefIndex !== -1) {
14
- var domain = baseUrl.substring(baseUrl.indexOf('//') + 2);
14
+ const domain = baseUrl.substring(baseUrl.indexOf('//') + 2);
15
15
 
16
- var href = token.attrs[hrefIndex][1];
16
+ let href = token.attrs[hrefIndex][1];
17
17
  href = href.substring(href.indexOf('//') > 0 ? href.indexOf('//') + 2 : 0);
18
18
 
19
- var isLocal = (href.indexOf('/') === 0 && href.indexOf('//') === -1) || href.indexOf(domain) === 0;
19
+ const isLocal = (href.indexOf('/') === 0 && href.indexOf('//') === -1) || href.indexOf(domain) === 0;
20
20
 
21
21
  if (!isLocal) {
22
- var relIndex = token.attrIndex('rel');
22
+ const relIndex = token.attrIndex('rel');
23
23
 
24
24
  if (relIndex === -1) {
25
25
  token.attrPush(['rel', 'nofollow']);
@@ -27,7 +27,7 @@ module.exports = function(md, args) {
27
27
  token.attrs[relIndex][1] = 'nofollow';
28
28
  }
29
29
 
30
- var targetIndex = token.attrIndex('target');
30
+ const targetIndex = token.attrIndex('target');
31
31
 
32
32
  if (targetIndex === -1) {
33
33
  token.attrPush(['target', '_blank']);
@@ -40,4 +40,4 @@ module.exports = function(md, args) {
40
40
 
41
41
  return defaultRender(tokens, idx, options, env, self);
42
42
  };
43
- };
43
+ };
package/package.json CHANGED
@@ -1,19 +1,20 @@
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",
7
7
  "markdown-it": "~14.1.0",
8
+ "markdown-it-collapsible": "~2.0.2",
8
9
  "mehdown-cowsay": "~1.1.6",
9
10
  "minimist": "~1.2.5",
10
11
  "natural": "~5.2.4",
11
12
  "probe-image-size": "~7.2.0",
12
13
  "rel-to-abs": "~0.1.0",
13
- "request": "~2.88.0",
14
+ "request": "~2.88.2",
14
15
  "roll": "~1.3.1",
15
16
  "shell-quote": "~1.8.0",
16
- "slug": "~9.0.0",
17
+ "slug": "~9.1.0",
17
18
  "textify": "~0.0.12",
18
19
  "youtube-search": "~1.1.4"
19
20
  },
@@ -33,5 +34,5 @@
33
34
  "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
34
35
  "test": "mocha --reporter spec test/*"
35
36
  },
36
- "version": "2.56.0"
37
+ "version": "2.58.0"
37
38
  }