diff --git a/src/PlainNormalizer/PlainNormalizer.ts b/src/PlainNormalizer/PlainNormalizer.ts index d9bf613d464f05c60675b5feb0d4cd8f8fa9c14e..b8fa4924392e23cddd0c90ae92c0396d51bf5fb4 100644 --- a/src/PlainNormalizer/PlainNormalizer.ts +++ b/src/PlainNormalizer/PlainNormalizer.ts @@ -3,23 +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 = cleanupImageText(text); text = normalizeTextSpacings(text); return text.trim(); @@ -58,7 +67,7 @@ const removeSeal = (plain: string, sealUrl: string): string => { .replace(new RegExp(sealRegexReversed), ""); }; -const cleanupImageText = (plain: string): string => { +export const cleanupImageText = (plain: string): string => { // For cases [image: IMAGE_NAME.EXTENSION] const sealRegex = `\\[(image:\\s)(.*)\\]`; 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, };