Skip to content
Snippets Groups Projects
Commit fea233fa authored by Igor Markin's avatar Igor Markin
Browse files

Add option to normalize image plain

parent 37770c30
Branches
Tags
1 merge request!27Gmail to Outlook - complex text + embeded image + attachments
......@@ -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)(.*)\\]`;
......
import { normalizePlainPart } from "./PlainNormalizer";
import { normalizePlainPart, cleanupImageText } from "./PlainNormalizer";
export default {
normalizePlain: normalizePlainPart,
cleanupImageText: cleanupImageText,
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment