@@ -48,3 +48,88 @@ Supported features:
48
48
* Paragraph first-line indents (as ` text- indent: #pt` )
49
49
* Idented regions (as ` padding- left: #pt` )
50
50
* Text alignment: left, right, center, justify (as ` text- align: ` )
51
+
52
+ ## rtfToHTML([opts], cb) → WritableStream
53
+
54
+ * opts - Optional options to pass to the HTML generator. See the section on [Options](#options) for details.
55
+ * cb - A callback accepting ` (err, html)` , see the section on the [Callback](#callback) for details.
56
+
57
+ Returns a WritableStream that you can pipe into.
58
+
59
+ ## rtfToHTML.fromStream(stream[, opts], cb)
60
+
61
+ * stream - A readable stream that should contain RTF.
62
+ * opts - Optional options to pass to the HTML generator. See the section on [Options](#options) for details.
63
+ * cb - A callback accepting ` (err, html)` , see the section on the [Callback](#callback) for details.
64
+
65
+ ## rtfToHTML.fromString(string[, opts], cb)
66
+
67
+ * string - A string containing RTF.
68
+ * opts - Optional options to pass to the HTML generator. See the section on [Options](#options) for details.
69
+ * cb - A callback accepting ` (err, html)` , see the section on the [Callback](#callback) for details.
70
+
71
+ ## Callback
72
+
73
+ <a name="callback">
74
+ rtfToHTML returns HTML produced from RTF using a standard Node.js style
75
+ callback, which should accept the following arguments: ` (err, html)` .
76
+
77
+ If we encounter an error in parsing then it will be set in ` err` . Otherwise
78
+ the resulting HTML will be in ` html ` .
79
+
80
+ ## Options
81
+
82
+ <a name =" options" >
83
+ Options are always optional. You can configure how HTML is generated with the following:
84
+
85
+ * paraBreaks - (Defaults to ` \n\n` ) Inserted between resulting paragraphs.
86
+ * paraTag - (Defaults to ` p` ) The tagname to use for paragraphs.
87
+ * template - A function that is used to generate the final HTML document, defaults to:
88
+ ` ` ` js
89
+ function outputTemplate (doc , defaults , content ) {
90
+ return ` <!DOCTYPE html>
91
+ <html>
92
+ <head>
93
+ <meta charset="UTF-8">
94
+ <style>
95
+ body {
96
+ margin-left: ${ doc .marginLeft / 20 } pt;
97
+ margin-right: ${ doc .marginRight / 20 } pt;
98
+ margin-top: ${ doc .marginTop / 20 } pt;
99
+ margin-bottom: ${ doc .marginBottom / 20 } pt;
100
+ font-size: ${ defaults .fontSize / 2 } pt;
101
+ text-indent: ${ defaults .firstLineIndent / 20 } pt;
102
+ }
103
+ </style>
104
+ </head>
105
+ <body>
106
+ ${ content .replace (/ \n / , ' \n ' )}
107
+ </body>
108
+ </html>`
109
+ }
110
+ ` ` `
111
+
112
+ You can also configure some of the starting (default) state of the output formatting with:
113
+
114
+ * disableFonts - Defaults to ` true ` . If you set this to ` false ` then we'll output font change information when we encounter it. This is
115
+ a bit broken due to our not supporting styles.
116
+ * fontSize - Defaults to the document-wide declared font size, or if that's missing, ` 24 ` .
117
+ * bold - Defaults to ` false `
118
+ * italic - Defaults to ` false `
119
+ * underline - Defaults to ` false `
120
+ * strikethrough - Defaults to ` false `
121
+ * foreground - Defaults to ` {red: 0 , blue: 0 , green: 0 }`
122
+ * background - Defaults to ` {red: 255 , blue: 255 , green: 255 }`
123
+ * firstLineIndent - Defaults to the document-wide value, or if that's missing, ` 0 ` . This is how far to indent the first line of new paragraphs.
124
+ * indent: Defaults to ` 0 `
125
+ * align: Defaults to ` left` .
126
+ * valign: Defaults to ` normal`
127
+
128
+ ## const rtfToHTML = require('rtf-to-html/rtf-to-html.js')
129
+ ## rtfToHTML(doc[, opts]) → HTML
130
+
131
+ This is internally how the other interfaces are implemented. Unlike the
132
+ other interfaces, this one is synchronous.
133
+
134
+ * doc - A parsed RTF document as produced by the ` rtf- parser` library.
135
+ * opts - Optional options, see the section on [Options](#options) for details.
0 commit comments