Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MIME Normalizer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
JS Toolbox
MIME Normalizer
Commits
1f3ce1b5
Commit
1f3ce1b5
authored
4 years ago
by
Igor Markin
Browse files
Options
Downloads
Patches
Plain Diff
Remove WordSection print function
parent
1b80f7f4
No related branches found
No related tags found
1 merge request
!18
Optimisations
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/HTMLNormalizer/HTMLNormalizer.ts
+8
-33
8 additions, 33 deletions
src/HTMLNormalizer/HTMLNormalizer.ts
src/HTMLNormalizer/strategies/outlook.ts
+0
-10
0 additions, 10 deletions
src/HTMLNormalizer/strategies/outlook.ts
with
8 additions
and
43 deletions
src/HTMLNormalizer/HTMLNormalizer.ts
+
8
−
33
View file @
1f3ce1b5
...
...
@@ -8,7 +8,6 @@ import {
import
{
amendOutlookNodes
,
cleanupOutlookElementAttributes
,
printOutlookElement
,
pruneOutlookElement
,
}
from
"
./strategies/outlook
"
;
import
{
EMAIL_VENDORS
}
from
"
../constants
"
;
...
...
@@ -36,10 +35,6 @@ const attributesCleanupFunctions = {
[
EMAIL_VENDORS
.
OUTLOOK
]:
cleanupOutlookElementAttributes
,
};
const
vendorPrintingFunctions
=
{
[
EMAIL_VENDORS
.
OUTLOOK
]:
printOutlookElement
,
};
export
const
normalizeVendorHtml
=
(
document
:
HTMLDocument
,
vendor
:
string
...
...
@@ -75,12 +70,7 @@ export const normalizeVendorHtml = (
cleanupHtmlNodeAttributes
(
document
,
elementAttributesCleanupFunction
);
}
/**
* Print nodes
*/
const
vendorPrintFunction
=
vendorPrintingFunctions
[
vendor
];
return
printHtmlChildren
(
mimeBody
,
vendorPrintFunction
,
0
);
return
printHtmlChildren
(
mimeBody
,
0
);
};
export
const
extractPseudoPlainPart
=
(
...
...
@@ -111,22 +101,18 @@ export const extractPseudoPlainPart = (
return
normalizedTextContent
;
};
export
const
printHtmlChildren
=
(
node
:
Node
,
printFunction
:
(
node
:
Node
)
=>
string
,
depth
:
number
):
string
=>
{
export
const
printHtmlChildren
=
(
node
:
Node
,
depth
:
number
):
string
=>
{
let
child
=
node
.
firstChild
;
if
(
!
child
)
{
return
""
;
}
if
(
child
==
node
.
lastChild
&&
child
.
nodeType
==
TEXT_NODE
)
{
return
printHtmlNode
(
child
,
printFunction
,
depth
);
return
printHtmlNode
(
child
,
depth
);
}
else
{
let
result
=
""
;
while
(
child
)
{
result
=
result
.
concat
(
printHtmlNode
(
child
,
printFunction
,
depth
));
result
=
result
.
concat
(
printHtmlNode
(
child
,
depth
));
child
=
child
.
nextSibling
;
}
...
...
@@ -134,20 +120,9 @@ export const printHtmlChildren = (
}
};
export
const
printHtmlNode
=
(
node
:
Node
,
printFunction
:
(
node
:
Node
)
=>
string
,
depth
:
number
):
string
=>
{
export
const
printHtmlNode
=
(
node
:
Node
,
depth
:
number
):
string
=>
{
let
result
=
""
;
if
(
printFunction
)
{
const
customPrintout
=
printFunction
(
node
);
if
(
customPrintout
)
{
return
customPrintout
;
}
}
switch
(
node
.
nodeType
)
{
case
TEXT_NODE
:
{
const
text
=
removeSpacesAndLinebreaks
(
node
.
textContent
);
...
...
@@ -160,7 +135,7 @@ export const printHtmlNode = (
break
;
}
case
DOCUMENT_NODE
:
result
+=
printHtmlChildren
(
node
,
printFunction
,
depth
);
result
+=
printHtmlChildren
(
node
,
depth
);
break
;
case
ELEMENT_NODE
:
result
+=
"
<
"
+
node
.
nodeName
;
...
...
@@ -174,7 +149,7 @@ export const printHtmlNode = (
});
if
(
node
.
firstChild
)
{
const
printout
=
printHtmlChildren
(
node
,
printFunction
,
depth
+
1
);
const
printout
=
printHtmlChildren
(
node
,
depth
+
1
);
if
(
printout
.
trim
().
length
===
0
)
{
result
+=
"
/>
"
;
}
else
{
...
...
@@ -261,7 +236,7 @@ export const escapeHtmlString = (string: string): string => {
let
escape
;
let
html
=
""
;
let
index
=
0
;
let
index
;
let
lastIndex
=
0
;
for
(
index
=
match
.
index
;
index
<
str
.
length
;
index
++
)
{
...
...
This diff is collapsed.
Click to expand it.
src/HTMLNormalizer/strategies/outlook.ts
+
0
−
10
View file @
1f3ce1b5
// TODO: Move this logic to amendOutlookNodes
import
{
printHtmlChildren
}
from
"
../HTMLNormalizer
"
;
import
{
ELEMENT_NODE
,
TEXT_NODE
}
from
"
../../constants
"
;
import
{
ATTRIBUTES_TO_KEEP
,
...
...
@@ -8,14 +6,6 @@ import {
}
from
"
./common
"
;
import
{
unwindTags
}
from
"
./nodesAmendingFunctions
"
;
export
const
printOutlookElement
=
(
node
:
Node
):
string
=>
{
if
(
node
.
nodeType
===
ELEMENT_NODE
)
{
if
((
node
as
HTMLElement
).
classList
.
contains
(
"
WordSection1
"
))
{
return
printHtmlChildren
(
node
,
null
,
0
);
}
}
};
/**
* Returns true if element should be completely removed
* @param element
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment