Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Fix regexp not removing multi-line comments #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ var regexSequences = [
// Remove XML stuffs and comments
[/<\?xml[\s\S]*?>/gi, ""],
[/<!doctype[\s\S]*?>/gi, ""],
[/<!--.*-->/gi, ""],
[/<!--[\s\S]*?-->/g, ""],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, not sure if anyone else is rusty but . does not match newlines. Adding newlines can be done with (.|\n) but that adds a capturing group so [\s\S] is used instead, which matches all whitespace and all non-whitespace characters which together form the set of all characters. No casing specifier is needed so that's dropped. *? is like * but non-greedy.


// SVG XML -> HTML5
[/\<([A-Za-z]+)([^\>]*)\/\>/g, "<$1$2></$1>"], // convert self-closing XML SVG nodes to explicitly closed HTML5 SVG nodes
[/\<([a-z]+)([^\>]*)\/\>/gi, "<$1$2></$1>"], // convert self-closing XML SVG nodes to explicitly closed HTML5 SVG nodes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case anyone else is a little rusty on their RegExps, this is a readability improvement: drop A-Z and make a-z case-insensitive with the i flag.

[/\s+/g, " "], // replace whitespace sequences with a single space
[/\> \</g, "><"] // remove whitespace between tags
];
Expand Down