Skip to content

Commit 9eddeb4

Browse files
authored
Merge pull request #358 from OneNoteDev/bug/large-enmbedded-fonts
Remove base64 encoded binaries in <style>
2 parents 402d678 + 4988489 commit 9eddeb4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/scripts/domParsers/domUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ export class DomUtils {
199199
return sanitizedHtml;
200200
}
201201

202+
/**
203+
* Many extensions inject their own stylings into the page, and generally that isn't a problem. But,
204+
* occasionally the styling includes a specific font, which can be very, very large. This method
205+
* removes any base64 encoded binaries defined in any <style> tags.
206+
*/
207+
public static removeStylesWithBase64EncodedBinaries(doc: Document): void {
208+
DomUtils.domReplacer(doc, "style", (node: HTMLElement) => {
209+
return node.innerHTML.indexOf("data:application") !== -1 ? undefined : node;
210+
});
211+
}
212+
202213
public static removeElementsNotSupportedInOnml(doc: Document): void {
203214
// For elements that cannot be converted into something equivalent in ONML, we remove them ...
204215
DomUtils.domReplacer(doc, DomUtils.tagsNotSupportedInOnml.join());
@@ -336,6 +347,7 @@ export class DomUtils {
336347
}
337348

338349
public static removeUnwantedItems(doc: Document): void {
350+
DomUtils.removeStylesWithBase64EncodedBinaries(doc);
339351
DomUtils.removeClipperElements(doc);
340352
DomUtils.removeUnwantedElements(doc);
341353
DomUtils.removeUnwantedAttributes(doc);

0 commit comments

Comments
 (0)