diff --git a/README.md b/README.md index 5840e4d..9eecea3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ node-rtf ======== -An RTF document creation library for node. Based on my old ActionScript3 implementation which has more documentation at http://code.google.com/p/rtflex/. \ No newline at end of file +An RTF document creation library for node. Forked from https://github.com/jrowny/node-rtf \ No newline at end of file diff --git a/lib/elements/group.js b/lib/elements/group.js index eaf093a..77e8d75 100644 --- a/lib/elements/group.js +++ b/lib/elements/group.js @@ -7,6 +7,11 @@ module.exports = GroupElement = function(name, format) { Element.apply(this, [format]); this.elements = []; this.name = name; + this.format = format; + + if(this.format && this.format.align) { + this.format.makeParagraph = true; + } }; GroupElement.subclass(Element); @@ -18,6 +23,8 @@ GroupElement.prototype.addElement = function(element){ GroupElement.prototype.getRTFCode = function(colorTable, fontTable, callback){ var tasks = []; var rtf = ""; + var self = this; // Store reference to 'this' so that it can be used in the async.parallel function + this.elements.forEach(function(el, i) { if (el instanceof Element){ tasks.push(function(cb) { el.getRTFCode(colorTable, fontTable, cb); }); @@ -30,8 +37,10 @@ GroupElement.prototype.getRTFCode = function(colorTable, fontTable, callback){ results.forEach(function(result) { rtf += result; }); + //formats the whole group - rtf = format.formatText(rtf, colorTable, fontTable, false); + rtf = self.format.formatText(rtf, colorTable, fontTable, false); // Use 'self' instead of 'this' + return callback(null, rtf); }); }; \ No newline at end of file diff --git a/lib/format.js b/lib/format.js index e5965d3..2d0f35c 100644 --- a/lib/format.js +++ b/lib/format.js @@ -88,7 +88,7 @@ Format.prototype.formatText = function(text, colorTable, fontTable, safeText){ //Add one because color 0 is null if(this.colorPos !== undefined && this.colorPos>=0) rtf+="\\cf" + (this.colorPos).toString(); if(this.fontSize >0) rtf += "\\fs" + (this.fontSize*2).toString(); - if(this.align.length > 0) rtf += align; + if(this.align.length > 0) rtf += this.align; if(this.leftIndent>0) rtf += "\\li" + (this.leftIndent*20).toString(); if(this.rightIndent>0) rtf += "\\ri" + this.rightIndent.toString(); diff --git a/lib/rtf-utils.js b/lib/rtf-utils.js index 4d4af2d..c45418a 100644 --- a/lib/rtf-utils.js +++ b/lib/rtf-utils.js @@ -34,8 +34,6 @@ function getRTFSafeText(text){ .replaceAll('{','\\{') .replaceAll('}','\\}') .replaceAll('~','\\~') - .replaceAll('-','\\-') - .replaceAll('_','\\_') //turns line breaks into \line commands .replaceAll('\n\r',' \\line ') .replaceAll('\n',' \\line ') diff --git a/lib/rtf.js b/lib/rtf.js index acf396e..7df21eb 100644 --- a/lib/rtf.js +++ b/lib/rtf.js @@ -82,6 +82,12 @@ RTF.prototype.addTab = function (groupName) { this.addCommand("\\tab", groupName); }; +//par shortcut +/* Ends the current paragraph and starts a new one. This includes resetting paragraph-level formatting like alignment, indentation, and other paragraph-specific settings. */ +RTF.prototype.addPar = function (groupName) { + this.addCommand("\\par", groupName); +}; + //gets the index of a group //TODO: make this more private by removing it from prototype and passing elements diff --git a/node-rtf.code-workspace b/node-rtf.code-workspace new file mode 100644 index 0000000..876a149 --- /dev/null +++ b/node-rtf.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/package.json b/package.json index f1ad69f..d62549e 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { - "name" : "rtf", - "version" : "0.0.4", + "name" : "@happy-doc/rtf", + "version" : "0.0.1", "description" : "Assists with creating rich text documents.", "main" : "./lib/rtf.js", - "author" : "Jonathan Rowny", + "author" : "HappyDoc", "repository" : { "type" : "git", - "url" : "https://github.com/jrowny/node-rtf.git" + "url" : "https://github.com/happy-doc/node-rtf.git" }, "keywords": [ "rtf",