rtf-parser
Advanced tools
Comparing version 1.0.5 to 1.1.0
{ | ||
"name": "rtf-parser", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "This is a general RTF parser. It takes a text stream and produces a document object representing the parsed document. In and of itself, this isn't super useful but it's the building block for other tools to convert RTF into other formats.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -58,2 +58,3 @@ # rtf-parser | ||
* Margins | ||
* Text direction | ||
@@ -99,1 +100,2 @@ ## NOTABLY MISSING | ||
* background: color | ||
* dir (rtl or ltr) |
@@ -41,16 +41,3 @@ 'use strict' | ||
this.group = null | ||
this.once('finish', () => { | ||
this.doc.addContent(new RTFParagraph()) | ||
const initialStyle = this.doc.content[0].style | ||
for (let prop of Object.keys(this.doc.style)) { | ||
let match = true | ||
for (let para of this.doc.content) { | ||
if (initialStyle[prop] !== para.style[prop]) { | ||
match = false | ||
break | ||
} | ||
} | ||
if (match) this.doc.style[prop] = initialStyle[prop] | ||
} | ||
}) | ||
this.once('prefinish', () => this.finisher()) | ||
} | ||
@@ -66,2 +53,16 @@ _write (cmd, encoding, done) { | ||
} | ||
finisher () { | ||
while (this.groupStack.length) this.cmd$groupEnd () | ||
const initialStyle = this.doc.content[0].style | ||
for (let prop of Object.keys(this.doc.style)) { | ||
let match = true | ||
for (let para of this.doc.content) { | ||
if (initialStyle[prop] !== para.style[prop]) { | ||
match = false | ||
break | ||
} | ||
} | ||
if (match) this.doc.style[prop] = initialStyle[prop] | ||
} | ||
} | ||
@@ -90,3 +91,3 @@ cmd$groupStart () { | ||
} | ||
process.emit('debug', 'GROUP END', endingGroup.type) | ||
process.emit('debug', 'GROUP END', endingGroup.type, endingGroup.get('ignorable')) | ||
} | ||
@@ -131,2 +132,10 @@ } | ||
// text direction | ||
ctrl$rtlch () { | ||
this.group.style.dir = 'rtl' | ||
} | ||
ctrl$ltrch () { | ||
this.group.style.dir = 'ltr' | ||
} | ||
// general style | ||
@@ -223,26 +232,43 @@ ctrl$par () { | ||
ctrl$fnil () { | ||
this.group.currentFont.family = 'nil' | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.family = 'nil' | ||
} | ||
} | ||
ctrl$froman () { | ||
this.group.currentFont.family = 'roman' | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.family = 'roman' | ||
} | ||
} | ||
ctrl$fswiss () { | ||
this.group.currentFont.family = 'swiss' | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.family = 'swiss' | ||
} | ||
} | ||
ctrl$fmodern () { | ||
this.group.currentFont.family = 'modern' | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.family = 'modern' | ||
} | ||
} | ||
ctrl$fscript () { | ||
this.group.currentFont.family = 'script' | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.family = 'script' | ||
} | ||
} | ||
ctrl$fdecor () { | ||
this.group.currentFont.family = 'decor' | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.family = 'decor' | ||
} | ||
} | ||
ctrl$ftech () { | ||
this.group.currentFont.family = 'tech' | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.family = 'tech' | ||
} | ||
} | ||
ctrl$fbidi () { | ||
this.group.currentFont.family = 'bidi' | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.family = 'bidi' | ||
} | ||
} | ||
ctrl$fcharset (code) { | ||
if (this.group instanceof FontTable) { | ||
let charset = null | ||
@@ -257,6 +283,9 @@ if (code === 1) { | ||
} | ||
this.group.currentFont.charset = charset | ||
this.group.currentFont.charset = charset | ||
} | ||
} | ||
ctrl$fprq (pitch) { | ||
this.group.currentFont.pitch = pitch | ||
if (this.group instanceof FontTable) { | ||
this.group.currentFont.pitch = pitch | ||
} | ||
} | ||
@@ -269,9 +298,15 @@ | ||
ctrl$red (value) { | ||
this.group.red = value | ||
if (this.group instanceof ColorTable) { | ||
this.group.red = value | ||
} | ||
} | ||
ctrl$blue (value) { | ||
this.group.blue = value | ||
if (this.group instanceof ColorTable) { | ||
this.group.blue = value | ||
} | ||
} | ||
ctrl$green (value) { | ||
this.group.green = value | ||
if (this.group instanceof ColorTable) { | ||
this.group.green = value | ||
} | ||
} | ||
@@ -301,2 +336,13 @@ ctrl$cf (value) { | ||
} | ||
// unsupported (and we need to ignore content) | ||
ctrl$stylesheet (value) { | ||
this.group.ignorable = true | ||
} | ||
ctrl$info (value) { | ||
this.group.ignorable = true | ||
} | ||
ctrl$mmathPr (value) { | ||
this.group.ignorable = true | ||
} | ||
} | ||
@@ -303,0 +349,0 @@ |
@@ -128,3 +128,3 @@ 'use strict' | ||
if (this.text === '') return | ||
this.push({type: 'text', value: this.text}) | ||
this.push({type: 'text', value: this.text, pos: this.char, row: this.row, col: this.col}) | ||
this.text = '' | ||
@@ -140,3 +140,6 @@ } | ||
value: this.controlWord, | ||
param: this.controlWordParam !== '' && Number(this.controlWordParam) | ||
param: this.controlWordParam !== '' && Number(this.controlWordParam), | ||
pos: this.char, | ||
row: this.row, | ||
col: this.col | ||
}) | ||
@@ -149,15 +152,15 @@ } | ||
this.emitText() | ||
this.push({type: 'group-start'}) | ||
this.push({type: 'group-start', pos: this.char, row: this.row, col: this.col}) | ||
} | ||
emitEndGroup () { | ||
this.emitText() | ||
this.push({type: 'group-end'}) | ||
this.push({type: 'group-end', pos: this.char, row: this.row, col: this.col}) | ||
} | ||
emitIgnorable () { | ||
this.emitText() | ||
this.push({type: 'ignorable'}) | ||
this.push({type: 'ignorable', pos: this.char, row: this.row, col: this.col}) | ||
} | ||
emitHexChar () { | ||
this.emitText() | ||
this.push({type: 'hexchar', value: this.hexChar}) | ||
this.push({type: 'hexchar', value: this.hexChar, pos: this.char, row: this.row, col: this.col}) | ||
this.hexChar = '' | ||
@@ -171,3 +174,3 @@ } | ||
this.emitText() | ||
this.push({type: 'end-paragraph'}) | ||
this.push({type: 'end-paragraph', pos: this.char, row: this.row, col: this.col}) | ||
} | ||
@@ -174,0 +177,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22379
693
100