Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jrowny/node-rtf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: happy-doc/node-rtf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 13 commits
  • 7 files changed
  • 2 contributors

Commits on Dec 13, 2024

  1. fixed the missing reference

    proteux committed Dec 13, 2024
    Copy the full SHA
    c53a7c0 View commit details
  2. fixed some issues around alignment (since that was clearly never test…

    …ed in the first place)
    proteux committed Dec 13, 2024
    Copy the full SHA
    782d78d View commit details

Commits on Dec 16, 2024

  1. published and good to go

    proteux committed Dec 16, 2024
    Copy the full SHA
    51f34cc View commit details

Commits on Dec 17, 2024

  1. Merge pull request #1 from happy-doc/bug/missing-reference

    fixed the missing reference
    jack-happydoc authored Dec 17, 2024
    Copy the full SHA
    e16de4e View commit details

Commits on Jan 10, 2025

  1. Copy the full SHA
    4b972a8 View commit details
  2. it clearly never worked

    proteux committed Jan 10, 2025
    Copy the full SHA
    180ba47 View commit details
  3. published

    proteux committed Jan 10, 2025
    Copy the full SHA
    72958a6 View commit details
  4. Merge pull request #2 from happy-doc/HDD-1443-Export-ready-document-w…

    …ith-indents
    
    HDD-1443 export ready document with indents
    jack-happydoc authored Jan 10, 2025
    Copy the full SHA
    6cd3a3a View commit details

Commits on Jan 13, 2025

  1. Copy the full SHA
    8451f3c View commit details
  2. 'splain yoruself boy

    proteux committed Jan 13, 2025
    Copy the full SHA
    0c6d0b8 View commit details
  3. drrr. knew he had a problem. chose the wrong fix. all of our headers …

    …had a space in front of them
    proteux committed Jan 13, 2025
    Copy the full SHA
    eede21c View commit details
  4. published new build

    proteux committed Jan 13, 2025
    Copy the full SHA
    0c8367d View commit details

Commits on Jan 14, 2025

  1. Merge pull request #3 from happy-doc/HDD-1443-Export-ready-fields-wit…

    …h-indents
    
    Hdd-1443 export ready fields with indents
    jack-happydoc authored Jan 14, 2025
    Copy the full SHA
    75e20c4 View commit details
Showing with 43 additions and 17 deletions.
  1. +1 −1 README.md
  2. +10 −1 lib/elements/group.js
  3. +6 −4 lib/format.js
  4. +0 −2 lib/rtf-utils.js
  5. +14 −5 lib/rtf.js
  6. +8 −0 node-rtf.code-workspace
  7. +4 −4 package.json
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
@@ -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);
});
};
10 changes: 6 additions & 4 deletions lib/format.js
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ Format.prototype.updateTables = function(colorTable, fontTable){

//some RTF elements require that they are wrapped, closed by a trailing 0 and must have a spacebefore the text.
function wrap(text, rtfwrapper){
return rtfwrapper + " " + text + rtfwrapper + "0";
return rtfwrapper + text + rtfwrapper + "0";
}

/**
@@ -88,12 +88,14 @@ 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();

//we don't escape text if there are other elements in it, so set a flag
var content = "";
//ensure that there is a space between the control character and the text
//otherwise things won't render properly
var content = " ";
if(safeText === undefined || safeText){
content += Utils.getRTFSafeText(text);
}else{
@@ -112,7 +114,7 @@ Format.prototype.formatText = function(text, colorTable, fontTable, safeText){
if(this.makeParagraph) rtf += "\\par";

//close doc
rtf+="}";
rtf+="}\n";

return rtf;
};
2 changes: 0 additions & 2 deletions lib/rtf-utils.js
Original file line number Diff line number Diff line change
@@ -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 ')
19 changes: 14 additions & 5 deletions lib/rtf.js
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@ module.exports = RTF = function () {
RTF.prototype.writeText = function (text, format, groupName) {
element = new TextElement(text, format);
if(groupName !== undefined && this._groupIndex(groupName) >= 0) {
this.elements[this._groupIndex(groupName)].push(element);
} else {
this.elements[this._groupIndex(groupName)].addElement(element);
} else {
this.elements.push(element);
}
};
@@ -82,16 +82,25 @@ 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
RTF.prototype._groupIndex = function (name) {
this.elements.forEach(function(el, i){
var index = -1;

this.elements.forEach(function(el, i) {
if(el instanceof GroupElement && el.name===name) {
return i;
index = i;
}
});
return -1;

return index;
};

RTF.prototype.createDocument = function (callback) {
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.3",
"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",