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
Merge requests
!1
Initial
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Initial
initial
into
master
Overview
0
Commits
16
Pipelines
2
Changes
10
Merged
Igor Markin
requested to merge
initial
into
master
4 years ago
Overview
0
Commits
16
Pipelines
2
Changes
10
Expand
0
0
Merge request reports
Viewing commit
52421c70
Prev
Next
Show latest version
10 files
+
479
−
6
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
10
Search (e.g. *.vue) (Ctrl+P)
52421c70
Implement initial version of HTML normalizer
· 52421c70
Igor Markin
authored
4 years ago
src/HTMLNormalizer/strategies/common.ts
0 → 100644
+
47
−
0
Options
const
DUMMY_QR_CODE_ID
=
"
dummyQrCode
"
;
export
const
ELEMENT_TYPES_TO_REMOVE
=
{
br
:
true
,
hr
:
true
};
export
const
ATTRIBUTES_TO_KEEP
=
{
alt
:
true
,
src
:
true
,
cite
:
true
,
data
:
true
,
datetime
:
true
,
href
:
true
,
value
:
true
,
};
/**
* Removes dummy QR code from HTML
* @param element
*/
const
isDummyQrCode
=
(
element
:
HTMLElement
):
boolean
=>
{
if
(
element
.
id
===
DUMMY_QR_CODE_ID
)
{
return
true
;
}
};
/**
* Decides whether node should be removed
* @param element
*/
export
const
pruneElement
=
(
element
:
HTMLElement
):
boolean
=>
{
if
(
isDummyQrCode
(
element
))
{
return
true
;
}
return
!!
ELEMENT_TYPES_TO_REMOVE
[
element
.
nodeName
.
toLowerCase
()];
};
export
const
cloneAnchorFromPane
=
(
a
:
HTMLAnchorElement
,
pane
:
HTMLElement
):
void
=>
{
try
{
const
url
=
new
URL
(
a
.
href
);
// If this is external url
if
(
url
.
host
&&
url
.
protocol
)
{
pane
.
parentNode
.
insertBefore
(
a
.
cloneNode
(
false
),
pane
);
}
}
catch
{
return
;
}
};
Loading