Skip to content

Commit

Permalink
fixed some issues around alignment (since that was clearly never test…
Browse files Browse the repository at this point in the history
…ed in the first place)
  • Loading branch information
proteux committed Dec 13, 2024
1 parent c53a7c0 commit 782d78d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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/.
An RTF document creation library for node. Forked from https://github.com/jrowny/node-rtf
11 changes: 10 additions & 1 deletion lib/elements/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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); });
Expand All @@ -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);
});
};
2 changes: 0 additions & 2 deletions lib/rtf-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ')
Expand Down
6 changes: 6 additions & 0 deletions lib/rtf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 782d78d

Please sign in to comment.