From c53a7c0a82b780e74926a9b9f3e425b1fa81239d Mon Sep 17 00:00:00 2001 From: Jack Whitehouse Date: Fri, 13 Dec 2024 15:11:26 -0700 Subject: [PATCH 1/3] fixed the missing reference --- lib/format.js | 2 +- node-rtf.code-workspace | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 node-rtf.code-workspace 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/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 From 782d78d93f2d97ee95dc7f8a7bb8dc99172701d7 Mon Sep 17 00:00:00 2001 From: Jack Whitehouse Date: Fri, 13 Dec 2024 16:40:01 -0700 Subject: [PATCH 2/3] fixed some issues around alignment (since that was clearly never tested in the first place) --- README.md | 2 +- lib/elements/group.js | 11 ++++++++++- lib/rtf-utils.js | 2 -- lib/rtf.js | 6 ++++++ package.json | 8 ++++---- 5 files changed, 21 insertions(+), 8 deletions(-) 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/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/package.json b/package.json index f1ad69f..f168422 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { - "name" : "rtf", - "version" : "0.0.4", + "name" : "@happy-doc/rtf", + "version" : "0.0.5", "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", From 51f34cc9f01ca4c07e7d79bfc95a326b5ccc18eb Mon Sep 17 00:00:00 2001 From: Jack Whitehouse Date: Mon, 16 Dec 2024 13:48:36 -0700 Subject: [PATCH 3/3] published and good to go --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f168422..d62549e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "@happy-doc/rtf", - "version" : "0.0.5", + "version" : "0.0.1", "description" : "Assists with creating rich text documents.", "main" : "./lib/rtf.js", "author" : "HappyDoc",