diff --git a/CHANGELOG.md b/CHANGELOG.md index 556ab8d820e1ea328b2bbe0fca24da71f50ca68b..fd7b3de83ad9e8d41e58c56cd789b1c8c04cc377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.3] - 2020-09-06 + +### Changed + +PlainNormalizer now strips `image:` prefix from plain representations of the images [outlokaddin#122](https://code.vereign.com/seal/clients/outlook-add-in/-/issues/122) + ## [1.0.2] - 2020-06-07 ### Added diff --git a/dist/PlainNormalizer/PlainNormalizer.d.ts b/dist/PlainNormalizer/PlainNormalizer.d.ts index 478c821ab21be102c420f6c70cfcab9799a30183..2e78fc4cec4196608228b38a69b3f36f2598a444 100644 --- a/dist/PlainNormalizer/PlainNormalizer.d.ts +++ b/dist/PlainNormalizer/PlainNormalizer.d.ts @@ -1,5 +1,7 @@ -export interface SealRemovalOptions { - sealUrl: string; +export interface Options { + sealUrl?: string; + normalizeImagePlain?: boolean; } -export declare const normalizePlainPart: (text: string, sealRemovalOptions?: SealRemovalOptions) => string; +export declare const normalizePlainPart: (text: string, options?: Options) => string; +export declare const cleanupImageText: (plain: string) => string; export declare const cleanupHiddenCharacters: (s: string) => string; diff --git a/dist/PlainNormalizer/PlainNormalizer.js b/dist/PlainNormalizer/PlainNormalizer.js index 5ffcd2695be84689132017d3e6829feed82f42be..dedea3fe27eaab78192b545289e6aa5d4b8708b8 100644 --- a/dist/PlainNormalizer/PlainNormalizer.js +++ b/dist/PlainNormalizer/PlainNormalizer.js @@ -1,14 +1,23 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanupHiddenCharacters = exports.normalizePlainPart = void 0; +exports.cleanupHiddenCharacters = exports.cleanupImageText = exports.normalizePlainPart = void 0; // this is a Node module. require is a must to work across different envs const URL = require("url-parse"); const utils_1 = require("../utils"); -const normalizePlainPart = (text, sealRemovalOptions) => { +const defaultOptions = { + normalizeImagePlain: true, +}; +const normalizePlainPart = (text, options) => { + options = options + ? Object.assign(defaultOptions, Object.assign({}, options)) + : defaultOptions; text = exports.cleanupHiddenCharacters(text); text = patchOutlookSafelinksWrappers(text); - if (sealRemovalOptions) { - text = removeSeal(text, sealRemovalOptions.sealUrl); + if (options === null || options === void 0 ? void 0 : options.sealUrl) { + text = removeSeal(text, options.sealUrl); + } + if (options === null || options === void 0 ? void 0 : options.normalizeImagePlain) { + text = exports.cleanupImageText(text); } text = utils_1.normalizeTextSpacings(text); return text.trim(); @@ -39,6 +48,12 @@ const removeSeal = (plain, sealUrl) => { .replace(new RegExp(sealRegex), "") .replace(new RegExp(sealRegexReversed), ""); }; +const cleanupImageText = (plain) => { + // For cases [image: IMAGE_NAME.EXTENSION] + const sealRegex = `\\[(image:\\s)(.*)\\]`; + return plain.replace(new RegExp(sealRegex), "[$2]"); +}; +exports.cleanupImageText = cleanupImageText; const cleanupHiddenCharacters = (s) => { const removeSymbols = new RegExp(/[\u200B]+/g); return s.replace(removeSymbols, ""); diff --git a/dist/PlainNormalizer/index.d.ts b/dist/PlainNormalizer/index.d.ts index 7fb02c437920fe2b32e76a694adef7edde2677b9..b6c35607403148f951f828819f0d5887fc237365 100644 --- a/dist/PlainNormalizer/index.d.ts +++ b/dist/PlainNormalizer/index.d.ts @@ -1,4 +1,5 @@ declare const _default: { - normalizePlain: (text: string, sealRemovalOptions?: import("./PlainNormalizer").SealRemovalOptions) => string; + normalizePlain: (text: string, options?: import("./PlainNormalizer").Options) => string; + cleanupImageText: (plain: string) => string; }; export default _default; diff --git a/dist/PlainNormalizer/index.js b/dist/PlainNormalizer/index.js index 2a16ea5ff2a36b0db5e4165f4ce70720652d9764..9d5f0b076664b32757ef5e8f3f1851467c4fa481 100644 --- a/dist/PlainNormalizer/index.js +++ b/dist/PlainNormalizer/index.js @@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); const PlainNormalizer_1 = require("./PlainNormalizer"); exports.default = { normalizePlain: PlainNormalizer_1.normalizePlainPart, + cleanupImageText: PlainNormalizer_1.cleanupImageText, }; diff --git a/package.json b/package.json index 2d4ac66a459cd4a5bd3236b3002e0290c8969e1a..9e85a50f042ba5045dd81e968ed6787685492512 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@vereign/mime-normalizer", "author": "Igor Markin <igor.markin@vereign.com>", "description": "A library that handles normalization of MIME plain and html parts", - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/PlainNormalizer/PlainNormalizer.ts b/src/PlainNormalizer/PlainNormalizer.ts index 9720a2db86a0727688f3be42fc0f9ca365448773..b8fa4924392e23cddd0c90ae92c0396d51bf5fb4 100644 --- a/src/PlainNormalizer/PlainNormalizer.ts +++ b/src/PlainNormalizer/PlainNormalizer.ts @@ -3,21 +3,32 @@ const URL = require("url-parse"); import { normalizeTextSpacings } from "../utils"; -export interface SealRemovalOptions { - sealUrl: string; +export interface Options { + sealUrl?: string; + normalizeImagePlain?: boolean; } -export const normalizePlainPart = ( - text: string, - sealRemovalOptions?: SealRemovalOptions -): string => { +const defaultOptions: Options = { + normalizeImagePlain: true, +}; + +export const normalizePlainPart = (text: string, options?: Options): string => { + options = options + ? Object.assign(defaultOptions, { ...options }) + : defaultOptions; + text = cleanupHiddenCharacters(text); text = patchOutlookSafelinksWrappers(text); - if (sealRemovalOptions) { - text = removeSeal(text, sealRemovalOptions.sealUrl); + if (options?.sealUrl) { + text = removeSeal(text, options.sealUrl); + } + + if (options?.normalizeImagePlain) { + text = cleanupImageText(text); } + text = normalizeTextSpacings(text); return text.trim(); @@ -56,6 +67,13 @@ const removeSeal = (plain: string, sealUrl: string): string => { .replace(new RegExp(sealRegexReversed), ""); }; +export const cleanupImageText = (plain: string): string => { + // For cases [image: IMAGE_NAME.EXTENSION] + const sealRegex = `\\[(image:\\s)(.*)\\]`; + + return plain.replace(new RegExp(sealRegex), "[$2]"); +}; + export const cleanupHiddenCharacters = (s: string): string => { const removeSymbols = new RegExp(/[\u200B]+/g); return s.replace(removeSymbols, ""); diff --git a/src/PlainNormalizer/index.ts b/src/PlainNormalizer/index.ts index 082282255540f20f513a3a0fe1588af33c949da6..21891a54d7d12c497c84b3362b23061c98e89677 100644 --- a/src/PlainNormalizer/index.ts +++ b/src/PlainNormalizer/index.ts @@ -1,5 +1,6 @@ -import { normalizePlainPart } from "./PlainNormalizer"; +import { normalizePlainPart, cleanupImageText } from "./PlainNormalizer"; export default { normalizePlain: normalizePlainPart, + cleanupImageText: cleanupImageText, };