- for ( var entity in replace ) {
- s = s.replace(new RegExp(entity, 'g'), '&' + replace[entity] + ';');
- }
-
- return s;
- }
-
- /**
- * Generic map function
- * @param iterable the array or object to be mapped
- * @param callback the callback function(element, key)
- * @returns array
- */
- function map(iterable, callback) {
- var mapped = new Array;
-
- for ( var i in iterable ) {
- if ( iterable.hasOwnProperty(i) ) {
- var value = callback.call(this, iterable[i], i);
-
- if ( value !== null ) mapped.push(value);
- }
- }
-
- return mapped;
- }
-
- /**
- * Generic reduce function
- * @param iterable array or object to be reduced
- * @param callback the callback function(initial, element, i)
- * @param initial the initial value
- * @return the reduced value
- */
- function reduce(iterable, callback, initial) {
- for ( var i in iterable ) {
- if ( iterable.hasOwnProperty(i) ) {
- initial = callback.call(this, initial, iterable[i], i);
- }
- }
-
- return initial;
- }
-
- /**
- * Utility method for creating a tag
- * @param name the tag name, e.g., 'text'
- * @param attrs the attribute string, e.g., name1="val1" name2="val2"
- * or attribute map, e.g., { name1 : 'val1', name2 : 'val2' }
- * @param content the content string inside the tag
- * @returns string of the tag
- */
- function tag(name, attrs, matrix, content) {
- if ( typeof content === 'undefined' || content === null ) {
- content = '';
- }
-
- if ( typeof attrs === 'object' ) {
- attrs = map(attrs, function(element, name) {
- if ( name === 'transform') return;
-
- return name + '="' + escapeXML(element) + '"';
- }).join(' ');
- }
-
- return '<' + name + ( matrix ? ' transform="matrix(' + matrix.toString().replace(/^matrix\(|\)$/g, '') + ')" ' : ' ' ) + attrs + '>' +
- content +
- '</' + name + '>' + "\n";
- }
-
- /**
- * @return object the style object
- */
- function extractStyle(node) {
- return {
- font: {
- family: node.attrs.font.replace(/^.*?"(\w+)".*$/, '$1'),
- size: typeof node.attrs['font-size'] === 'undefined' ? null : node.attrs['font-size'],
- anchor : typeof node.attrs['text-anchor'] === 'undefined' ? null : node.attrs['text-anchor'],
- }
- };
- }
-
- /**
- * @param style object from style()
- * @return string
- */
- function styleToString(style) {
- // TODO figure out what is 'normal'
-
+ for (var entity in replace) {
+ s = s.replace(new RegExp(entity, 'g'), '&' + replace[entity] + ';');
+ }
+
+ return s;
+ }
+
+ /**
+ * Generic map function
+ * @param iterable the array or object to be mapped
+ * @param callback the callback function(element, key)
+ * @returns array
+ */
+ function map(iterable, callback) {
+ var mapped = new Array;
+
+ for (var i in iterable) {
+ if (iterable.hasOwnProperty(i)) {
+ var value = callback.call(this, iterable[i], i);
+
+ if (value !== null)
+ mapped.push(value);
+ }
+ }
+
+ return mapped;
+ }
+
+ /**
+ * Generic reduce function
+ * @param iterable array or object to be reduced
+ * @param callback the callback function(initial, element, i)
+ * @param initial the initial value
+ * @return the reduced value
+ */
+ function reduce(iterable, callback, initial) {
+ for (var i in iterable) {
+ if (iterable.hasOwnProperty(i)) {
+ initial = callback.call(this, initial, iterable[i], i);
+ }
+ }
+
+ return initial;
+ }
+
+ /**
+ * Utility method for creating a tag
+ * @param name the tag name, e.g., 'text'
+ * @param attrs the attribute string, e.g., name1="val1" name2="val2"
+ * or attribute map, e.g., { name1 : 'val1', name2 : 'val2' }
+ * @param content the content string inside the tag
+ * @returns string of the tag
+ */
+ function tag(name, attrs, matrix, content) {
+ if (typeof content === 'undefined' || content === null) {
+ content = '';
+ }
+
+ if (typeof attrs === 'object') {
+ attrs = map(attrs, function (element, name) {
+ if (name === 'transform')
+ return;
+
+ return name + '="' + escapeXML(element) + '"';
+ }).join(' ');
+ }
+
+ return '<' + name + (matrix ? ' transform="matrix(' + matrix.toString().replace(/^matrix\(|\)$/g, '') + ')" ' : ' ') + attrs + '>' +
+ content +
+ '</' + name + '>' + "\n";
+ }
+
+ /**
+ * @return object the style object
+ */
+ function extractStyle(node) {
+ return {
+ font: {
+ family: node.attrs.font.replace(/^.*?"(\w+)".*$/, '$1'),
+ size: typeof node.attrs['font-size'] === 'undefined' ? null : node.attrs['font-size'],
+ anchor: typeof node.attrs['text-anchor'] === 'undefined' ? null : node.attrs['text-anchor'],
+ }
+ };
+ }
+
+ /**
+ * @param style object from style()
+ * @return string
+ */
+ function styleToString(style) {
+ // TODO figure out what is 'normal'
+