Skip to content

Commit

Permalink
restore HTML entities back (fix svg#80 + svg#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsweet committed Dec 17, 2012
1 parent 3ca643d commit 4595208
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 20 deletions.
44 changes: 25 additions & 19 deletions .svgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,29 @@ svg2js:

js2svg:

doctypeStart: '<!DOCTYPE'
doctypeEnd: '>'
procInstStart: '<?'
procInstEnd: '?>'
tagOpenStart: '<'
tagOpenEnd: '>'
tagCloseStart: '</'
tagCloseEnd: '>'
tagShortStart: '<'
tagShortEnd: '/>'
attrStart: '="'
attrEnd: '"'
commentStart: '<!--'
commentEnd: '-->'
cdataStart: '<![CDATA['
cdataEnd: ']]>'
textStart: ''
textEnd: ''
indent: ' '
doctypeStart: "<!DOCTYPE"
doctypeEnd: ">"
procInstStart: "<?"
procInstEnd: "?>"
tagOpenStart: "<"
tagOpenEnd: ">"
tagCloseStart: "</"
tagCloseEnd: ">"
tagShortStart: "<"
tagShortEnd: "/>"
attrStart: "=\""
attrEnd: "\""
commentStart: "<!--"
commentEnd: "-->"
cdataStart: "<![CDATA["
cdataEnd: "]]>"
textStart: ""
textEnd: ""
indent: " "
entities:
"&": "&amp;"
"'": "&apos;"
"\"": "&quot;"
">": "&gt;"
"<": "&lt;"
pretty: false
5 changes: 5 additions & 0 deletions lib/svgo/js2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ var Converter = INHERIT(/** @lends Nodes.prototype */{
*/
createText: function(text) {

// convert entities back
for (var entity in this.config.entities) {
text = text.split(entity).join(this.config.entities[entity]);
}

return this.createIndent() +
this.config.textStart +
text +
Expand Down
36 changes: 35 additions & 1 deletion plugins/removeUnusedIDs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,42 @@ var referencesProps = require('./_collections').referencesProps,
regReferencesHref = /^#(.+?)$/,
styleOrScript = ['style', 'script'];

function replaceLast(str, char) {
str = str.split('');
str[str.length - 1] = char;
return str.join('');
}

function replaceFirst(str, char) {
str = str.split('');
str[0] = char;
return str.join('');
}

function generateID(prev) {
var next;

if (prev.charCodeAt(prev.length - 1) === 122) {
next = replaceAt(prev, 'A');
} else if (prev.charCodeAt(prev.length - 1) === 90) {
next = replaceAt(prev, 'A');
} else {
next = replaceAt(prev, String.fromCharCode(prev.charCodeAt(prev.length - 1) + 1));
}

// if (prev.length === 1) {
// if (prev.charCodeAt(0) === 122) {
// next = String.fromCharCode(65);
// } else if (prev.charCodeAt(0) === 90) {
// next = 'aa';
// }
// } else if (prev.length === 2) {

// }
}

/**
* Remove unused ID
* Remove unused IDs
* (only if there are no any <style> or <script>).
*
* @param {Object} item current iteration item
Expand Down
4 changes: 4 additions & 0 deletions test/plugins/cleanupAttrs.02.orig.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/plugins/cleanupAttrs.02.should.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4595208

Please sign in to comment.