@salesforcedevs/sfdocs-image-transformer
Advanced tools
Comparing version 1.0.5-fix-alpha to 1.0.5-fix-alpha1
@@ -8,6 +8,2 @@ import { VFile } from 'vfile'; | ||
}; | ||
/** Function to check if the provided imagePath is a local path or not | ||
* If the URL start with https:// or www. or /, then this function returns | ||
* false (meaning, these path are treated as external URL's) | ||
*/ | ||
export declare function isInternalPath(imagePath: string): boolean; | ||
@@ -14,0 +10,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateImagePath = exports.isInternalPath = void 0; | ||
/** Function to check if the provided imagePath is a local path or not | ||
* If the URL start with https:// or www. or /, then this function returns | ||
* false (meaning, these path are treated as external URL's) | ||
*/ | ||
// Function to check if the provided imagePath is a local path or not | ||
function isInternalPath(imagePath) { | ||
return imagePath && !(imagePath.match(/^(https?:\/\/|www\.|\/).*/)); | ||
return imagePath && !(imagePath.match(/^(https?:\/\/|www\.).*/)); | ||
} | ||
@@ -11,0 +8,0 @@ exports.isInternalPath = isInternalPath; |
@@ -15,2 +15,11 @@ "use strict"; | ||
/** | ||
* Function to check if the image path is already transformed, | ||
* if path is transformed we will not transform them again. | ||
* @param imagePath | ||
* @returns true/false | ||
*/ | ||
function isTransformedPath(imagePath) { | ||
return imagePath && path_1.default.isAbsolute(imagePath) && !imagePath.startsWith('/media'); | ||
} | ||
/** | ||
* Function to transform the internal image paths to include ./ as a prefix. | ||
@@ -25,3 +34,3 @@ * If an image path is '../media/maps.png', then it will be transformed to './../media/maps.png' | ||
const imagePath = node.url; | ||
if ((0, image_cdn_mapper_1.isInternalPath)(imagePath) && !imagePath.startsWith('./')) { | ||
if ((0, image_cdn_mapper_1.isInternalPath)(imagePath) && !imagePath.startsWith('./') && !isTransformedPath(imagePath)) { | ||
const prefix = path_1.default.isAbsolute(imagePath) ? '.' : './'; | ||
@@ -28,0 +37,0 @@ node.url = prefix + imagePath; |
{ | ||
"version": "1.0.5-fix-alpha", | ||
"version": "1.0.5-fix-alpha1", | ||
"name": "@salesforcedevs/sfdocs-image-transformer", | ||
@@ -4,0 +4,0 @@ "description": "Salesforce Docs markdown plugin for image transormation", |
@@ -166,4 +166,14 @@ import vfile, { VFile } from 'vfile'; | ||
}) | ||
}); | ||
test('absolute paths should not be prefixed with "./" if not path is already transformed', () => { | ||
const markdown = '![SalesforceDocs](/user/test/media/salesforcedocs.png)'; | ||
const result = processMarkdown(markdown); | ||
const contents = result.contents; | ||
expect(contents).toEqual( | ||
'<p><img src="/user/test/media/salesforcedocs.png" alt="SalesforceDocs"></p>', | ||
); | ||
}); | ||
}); |
@@ -11,8 +11,5 @@ import { VFile } from 'vfile'; | ||
/** Function to check if the provided imagePath is a local path or not | ||
* If the URL start with https:// or www. or /, then this function returns | ||
* false (meaning, these path are treated as external URL's) | ||
*/ | ||
// Function to check if the provided imagePath is a local path or not | ||
export function isInternalPath(imagePath: string): boolean { | ||
return imagePath && !(imagePath.match(/^(https?:\/\/|www\.|\/).*/)); | ||
return imagePath && !(imagePath.match(/^(https?:\/\/|www\.).*/)); | ||
} | ||
@@ -19,0 +16,0 @@ |
@@ -19,2 +19,12 @@ import { Transformer } from 'unified'; | ||
/** | ||
* Function to check if the image path is already transformed, | ||
* if path is transformed we will not transform them again. | ||
* @param imagePath | ||
* @returns true/false | ||
*/ | ||
function isTransformedPath(imagePath: string): boolean { | ||
return imagePath && path.isAbsolute(imagePath) && !imagePath.startsWith('/media'); | ||
} | ||
/** | ||
* Function to transform the internal image paths to include ./ as a prefix. | ||
@@ -29,3 +39,3 @@ * If an image path is '../media/maps.png', then it will be transformed to './../media/maps.png' | ||
const imagePath = node.url; | ||
if (isInternalPath(imagePath) && !imagePath.startsWith('./')) { | ||
if (isInternalPath(imagePath) && !imagePath.startsWith('./') && !isTransformedPath(imagePath)) { | ||
const prefix = path.isAbsolute(imagePath) ? '.' : './'; | ||
@@ -32,0 +42,0 @@ node.url = prefix + imagePath; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
52680
555
0