Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace sax library with saxes library #1281

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
Empty file modified bin/svgo
100755 → 100644
Empty file.
Empty file modified lib/svgo.js
100755 → 100644
Empty file.
28 changes: 14 additions & 14 deletions lib/svgo/svg2js.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var SAX = require('sax'),
var SAXES = require('saxes'),
JSAPI = require('./jsAPI.js'),
CSSClassList = require('./css-class-list'),
CSSStyleDeclaration = require('./css-style-declaration'),
Expand All @@ -23,7 +23,7 @@ var config = {
*/
module.exports = function(data, callback) {

var sax = SAX.parser(config.strict, config),
var saxes = new SAXES.SaxesParser(config.strict, config),
root = new JSAPI({ elem: '#document', content: [] }),
current = root,
stack = [root],
Expand All @@ -40,7 +40,7 @@ module.exports = function(data, callback) {

}

sax.ondoctype = function(doctype) {
saxes.ondoctype = function(doctype) {

pushToContent({
doctype: doctype
Expand All @@ -53,36 +53,36 @@ module.exports = function(data, callback) {
entityDeclaration.lastIndex = subsetStart;

while ((entityMatch = entityDeclaration.exec(data)) != null) {
sax.ENTITIES[entityMatch[1]] = entityMatch[2] || entityMatch[3];
saxes.ENTITIES[entityMatch[1]] = entityMatch[2] || entityMatch[3];
}
}
};

sax.onprocessinginstruction = function(data) {
saxes.onprocessinginstruction = function(data) {

pushToContent({
processinginstruction: data
});

};

sax.oncomment = function(comment) {
saxes.oncomment = function(comment) {

pushToContent({
comment: comment.trim()
});

};

sax.oncdata = function(cdata) {
saxes.oncdata = function(cdata) {

pushToContent({
cdata: cdata
});

};

sax.onopentag = function(data) {
saxes.onopentag = function(data) {

var elem = {
elem: data.name,
Expand Down Expand Up @@ -126,7 +126,7 @@ module.exports = function(data, callback) {

};

sax.ontext = function(text) {
saxes.ontext = function(text) {

if (/\S/.test(text) || textContext) {

Expand All @@ -141,7 +141,7 @@ module.exports = function(data, callback) {

};

sax.onclosetag = function() {
saxes.onclosetag = function() {

var last = stack.pop();

Expand All @@ -154,7 +154,7 @@ module.exports = function(data, callback) {

};

sax.onerror = function(e) {
saxes.onerror = function(e) {

e.message = 'Error in parsing SVG: ' + e.message;
if (e.message.indexOf('Unexpected end') < 0) {
Expand All @@ -163,7 +163,7 @@ module.exports = function(data, callback) {

};

sax.onend = function() {
saxes.onend = function() {

if (!this.error) {
callback(root);
Expand All @@ -174,12 +174,12 @@ module.exports = function(data, callback) {
};

try {
sax.write(data);
saxes.write(data);
} catch (e) {
callback({ error: e.message });
parsingError = true;
}
if (!parsingError) sax.close();
if (!parsingError) saxes.close();

function trim(elem) {
if (!elem.content) return elem;
Expand Down
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"example": "./examples"
},
"scripts": {
"test": "set NODE_ENV=test && mocha",
"test": "set NODE_ENV=test && mocha --timeout 10000",
"lint": "jshint --show-non-errors .",
"jshint": "npm run lint"
},
Expand All @@ -57,7 +57,7 @@
"js-yaml": "^3.13.1",
"mkdirp": "~0.5.1",
"object.values": "^1.1.0",
"sax": "~1.2.4",
"saxes": "^5.0.1",
"stable": "^0.1.8",
"unquote": "~1.1.1",
"util.promisify": "~1.0.0"
Expand Down
Empty file modified plugins/minifyStyles.js
100755 → 100644
Empty file.
Empty file modified plugins/prefixIds.js
100755 → 100644
Empty file.
Empty file modified test/plugins/minifyStyles.01.svg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified test/plugins/minifyStyles.10.svg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.