marked-images 2.2.0 → 3.0.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2015-2020 Jürgen Leschner -- github.com/jldec
3
+ Copyright (c) 2015-2022 Jürgen Leschner -- github.com/jldec
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -11,8 +11,11 @@ npm install marked-images
11
11
  ```
12
12
 
13
13
  ## usage
14
- *NOTE: breaking change:*
15
- As of v2.0.0, this library uses the [`marked.use()`](https://marked.js.org/#/USING_PRO.md#use) plugin api.
14
+
15
+ *NOTE: breaking changes:*
16
+
17
+ - As of v2.0.0, this library uses the [`marked.use()`](https://marked.js.org/#/USING_PRO.md#use) plugin api.
18
+ - As of v3.0.0, since [marked v4.x](https://github.com/markedjs/marked/releases/tag/v4.0.0) the `marked()` function is no longer the default export. CommonJS code which does `marked = require(marked)` should be changed to call `marked.marked(<markdown-string>)` instead of `marked()`.
16
19
 
17
20
  ```javascript
18
21
  var marked = require('marked');
@@ -29,7 +32,7 @@ var opts = {
29
32
 
30
33
  marked.use(markedImages(opts));
31
34
 
32
- var html = marked(markdown);
35
+ var html = marked.marked(markdown);
33
36
  ```
34
37
 
35
38
  #### simple width and height
@@ -58,6 +61,18 @@ generates:
58
61
  <img src="src" alt="" width="1" height="2" align="right" title="title text">
59
62
  ```
60
63
 
64
+ #### CSS classnames
65
+ .{classname}
66
+
67
+ ```md
68
+ ![Alt-text](src ".class1 .class-2 .class_3 10x10"
69
+ ```
70
+
71
+ generates:
72
+ ```html
73
+ <img src="src" alt="Alt-text" width="10" height="10" class="class1 class-2 class_3">
74
+ ```
75
+
61
76
  #### vimeo link
62
77
  start src with 'vimeo/' e.g.
63
78
 
package/marked-images.js CHANGED
@@ -1,15 +1,21 @@
1
1
  /**
2
2
  * marked-images.js
3
3
  *
4
- * marked.js plugin renderer for images
5
- * generate width="a" and height="b" attributes from axb pattern in title string E.g ![](src "100x50")
6
- * attr="x" from attr=x (with no "") e.g. ![](src "width=100 height=50 align=right")
7
- * vimeo standard <iframe.. ></iframe> from ![](vimeo/nnn) where nnn is the vimeo id
4
+ * marked.js plugin for images
5
+ *
6
+ * looks for href pattern "vimeo/nnn" where nnn is the vimeo id
7
+ * produces <iframe.. ></iframe>
8
+ *
9
+ * splits title into whitespace-separated tokens
10
+ * looks in each token for patterns used to generate <img> or <iframe> attributes
11
+ * - pattern axb E.g ![](src "100x50") => width="100" height="50"
12
+ * - pattern attr=value (with no quotes) E.g. ![](src "width=100 height=50 align=right")
13
+ * - pattern .className E.g. ![](src ".foo .bar") => class="foo bar"
8
14
  *
9
15
  * usage: marked.use(markedImages(opts))
10
16
  *
11
17
  * original function: copyright Christopher Jeffrey -- https://github.com/markedjs/marked (MIT License)
12
- * extension copyright 2015-2020, Jürgen Leschner - github.com/jldec/ - MIT license
18
+ * extension Copyright (c) 2015-2022 Jürgen Leschner - github.com/jldec/ - MIT license
13
19
  *
14
20
  **/
15
21
 
@@ -43,12 +49,22 @@ module.exports = function markedImages(opts) {
43
49
 
44
50
  var a = (title && title.split(/\s+/)) || [];
45
51
  var b = [];
52
+ var classNames = [];
46
53
  var m;
47
54
  a.forEach(function(w) {
48
55
  if ((m = w.match(/^(\d+)x(\d+)$/))) return (out += ' width="' + m[1] + '" height="' + m[2] + '"');
49
- if ((m = w.match(/^(\w+)=([\w-]+)$/))) return (out += ' ' + m[1] + '="' + m[2] + '"');
56
+ if ((m = w.match(/^(\w+)=([\w-]+)$/))) {
57
+ if (m[1] === 'class') return classNames.push(m[2]);
58
+ return (out += ' ' + m[1] + '="' + m[2] + '"');
59
+ }
60
+ if ((m = w.match(/^\.([\w-]+)$/))) return classNames.push(m[1]);
50
61
  if (w) return b.push(w);
51
62
  });
63
+
64
+ if (classNames.length) {
65
+ out += ' class="' + classNames.join(' ') + '"';
66
+ }
67
+
52
68
  title = b.join(' ');
53
69
 
54
70
  if (title) {
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "marked-images",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "Simple marked renderer for image attributes in markdown. Also generates vimeo links.",
5
5
  "main": "marked-images.js",
6
6
  "peerDependencies": {
7
- "marked": "^1.2.5"
7
+ "marked": "^4.0.10"
8
8
  },
9
9
  "dependencies": {
10
10
  "lodash.startswith": "^4.2.1"
11
11
  },
12
12
  "devDependencies": {
13
- "eslint": "^7.13.0",
14
- "marked": "^1.2.5",
15
- "tape": "^5.0.1"
13
+ "eslint": "^8.7.0",
14
+ "marked": "^4.0.10",
15
+ "tape": "^5.4.1"
16
16
  },
17
17
  "files": [
18
18
  "marked-images.js"