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

Properly handle spaces in plain part

parent 0babe26a
No related branches found
No related tags found
1 merge request!17Populate attachments before normalisation
......@@ -205,7 +205,7 @@ Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Stephan Morphis has shared OneDrive files with you. To view them, click the=
links below.
links below.
<https://1drv.ms/u/s!Au0bzLX4nSlWiDaBztIacMtR0TFd>
[https://r1.res.office365.com/owa/prem/images/dc-generic_20.png]<https://1d=
rv.ms/u/s!Au0bzLX4nSlWiDaBztIacMtR0TFd>
......
......@@ -206,7 +206,7 @@ Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Stephan Morphis has shared OneDrive files with you. To view them, click the=
links below.
links below.
<https://1drv.ms/u/s!Au0bzLX4nSlWiDaBztIacMtR0TFd>
[https://r1.res.office365.com/owa/prem/images/dc-generic_20.png]<https://1d=
rv.ms/u/s!Au0bzLX4nSlWiDaBztIacMtR0TFd>
......
......@@ -210,7 +210,7 @@ Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Stephan Morphis has shared OneDrive files with you. To view them, click the=
links below.
links below.
<https://1drv.ms/u/s!Au0bzLX4nSlWlj-_pxZ0QmCUigL4>
[https://r1.res.office365.com/owa/prem/images/dc-png_20.png]<https://1drv.m=
s/u/s!Au0bzLX4nSlWlj-_pxZ0QmCUigL4>
......
// this is a Node module. require is a must to work across different envs
const URL = require("url-parse");
import { removeSpacesAndLinebreaks } from "../utils";
import { normalizeTextSpacings } from "../utils";
export const normalizePlainPart = (text: string): string => {
text = cleanupHiddenCharacters(text);
text = removeListBullets(text);
text = removeSpacesAndLinebreaks(text);
text = removeQRCodes(text);
text = normalizeTextSpacings(text);
text = patchOutlookSafelinksWrappers(text);
return text;
return text.trim();
};
const patchOutlookSafelinksWrappers = (text: string) => {
......@@ -29,10 +31,15 @@ const patchOutlookSafelinksWrappers = (text: string) => {
const removeQRCodes = (s: string): string => {
return s
.replace(/\[(image:)*qrcode.png]\s*<https:\/\/.+?>/g, "")
.replace(/\[(image:\s)*qrcode.png]\s*<https:\/\/.+?>/g, "")
.replace(/<https:\/\/.+?>\s*\[(image: )*qrcode.png]/g, "");
};
const removeListBullets = (s: string): string => {
return s.replace("\n[o§]\n+/g", "");
};
export const cleanupHiddenCharacters = (s: string): string => {
const removeSymbols = new RegExp(/[\u200B]+/g);
return s.replace(removeSymbols, "");
};
......@@ -3,3 +3,7 @@ export const removeSpacesAndLinebreaks = (s: string): string => {
return s.replace(removeSymbols, "").trim();
};
export const normalizeTextSpacings = (s: string): string => {
return s.replace(/[\r\n\v\s]+/g, " ");
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment