@tryghost/url-utils 2.0.8 → 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.
@@ -8,6 +8,18 @@ function extractSrcsetUrls(srcset = '') {
8
8
  });
9
9
  }
10
10
 
11
+ function extractStyleUrls(style = '') {
12
+ const urls = [];
13
+ const regex = /url\(['|"]([^)]+)['|"]\)/g;
14
+ let match;
15
+
16
+ while ((match = regex.exec(style)) !== null) {
17
+ urls.push(match[1]);
18
+ }
19
+
20
+ return urls;
21
+ }
22
+
11
23
  function htmlTransform(html = '', siteUrl, transformFunction, itemPath, _options) {
12
24
  const defaultOptions = {assetsOnly: false, secure: false};
13
25
  const options = Object.assign({}, defaultOptions, _options || {});
@@ -42,7 +54,7 @@ function htmlTransform(html = '', siteUrl, transformFunction, itemPath, _options
42
54
  }
43
55
 
44
56
  // find all of the relative url attributes that we care about
45
- ['href', 'src', 'srcset'].forEach((attributeName) => {
57
+ ['href', 'src', 'srcset', 'style'].forEach((attributeName) => {
46
58
  htmlContent('[' + attributeName + ']').each((ix, el) => {
47
59
  // ignore <stream> elems and html inside of <code> elements
48
60
  if (el.name === 'stream' || htmlContent(el).closest('code').length) {
@@ -57,8 +69,14 @@ function htmlTransform(html = '', siteUrl, transformFunction, itemPath, _options
57
69
  el = htmlContent(el);
58
70
  const originalValue = el.attr(attributeName);
59
71
 
60
- if (attributeName === 'srcset') {
61
- const urls = extractSrcsetUrls(originalValue);
72
+ if (attributeName === 'srcset' || attributeName === 'style') {
73
+ let urls;
74
+
75
+ if (attributeName === 'srcset') {
76
+ urls = extractSrcsetUrls(originalValue);
77
+ } else {
78
+ urls = extractStyleUrls(originalValue);
79
+ }
62
80
  const absoluteUrls = urls.map(url => transformFunction(url, siteUrl, itemPath, options));
63
81
  let transformedValue = originalValue;
64
82
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/url-utils",
3
- "version": "2.0.8",
3
+ "version": "2.1.0",
4
4
  "repository": "https://github.com/TryGhost/SDK/tree/master/packages/url-utils",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -33,5 +33,5 @@
33
33
  "remark-footnotes": "^1.0.0",
34
34
  "unist-util-visit": "^2.0.0"
35
35
  },
36
- "gitHead": "36ffe70168eb2ad3eaefa0dc63a35697b284c9e7"
36
+ "gitHead": "8bfb11a7576f3a09aa2a4d633933bb8f341d9329"
37
37
  }