Skip to content

Commit

Permalink
Merge pull request #1 from happy-doc/bug/missing-reference
Browse files Browse the repository at this point in the history
fixed the missing reference
  • Loading branch information
jack-happydoc authored Dec 17, 2024
2 parents 55503df + 51f34cc commit e16de4e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 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: 1 addition & 1 deletion lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
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: 8 additions & 0 deletions node-rtf.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
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.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",
Expand Down

0 comments on commit e16de4e

Please sign in to comment.