1
+ 'use strict' ;
1
2
2
3
var assert = require ( 'assert' ) ,
3
- Stream = require ( 'stream' ) ,
4
- inherits = require ( 'util' ) . inherits ;
4
+ Stream = require ( 'stream' ) ,
5
+ inherits = require ( 'util' ) . inherits ;
5
6
6
7
7
8
/*
8
9
* This filter consumes a stream of characters and emits one string per line.
9
10
*/
10
11
function LineSplitter ( ) {
11
12
var self = this ,
12
- buffer = "" ;
13
+ buffer = '' ;
13
14
14
15
Stream . call ( this ) ;
15
16
this . writable = true ;
@@ -39,32 +40,30 @@ inherits(LineSplitter, Stream);
39
40
*/
40
41
function ParagraphParser ( ) {
41
42
var self = this ,
42
- block_is_license_block = false ,
43
- block_has_c_style_comment ,
44
- is_first_line_in_paragraph ,
45
- paragraph_line_indent ,
46
- paragraph ;
47
-
48
- Stream . call ( this ) ;
49
- this . writable = true ;
50
-
51
- resetBlock ( false ) ;
52
-
53
- this . write = function ( data ) {
54
- parseLine ( data + '' ) ;
55
- return true ;
56
- } ;
57
-
58
- this . end = function ( data ) {
59
- if ( data ) {
60
- parseLine ( data + '' ) ;
61
- }
62
- flushParagraph ( ) ;
63
- self . emit ( 'end' ) ;
64
- } ;
43
+ block_is_license_block = false ,
44
+ block_has_c_style_comment ,
45
+ paragraph_line_indent ,
46
+ paragraph ;
47
+
48
+ Stream . call ( this ) ;
49
+ this . writable = true ;
50
+
51
+ resetBlock ( false ) ;
52
+
53
+ this . write = function ( data ) {
54
+ parseLine ( data + '' ) ;
55
+ return true ;
56
+ } ;
57
+
58
+ this . end = function ( data ) {
59
+ if ( data ) {
60
+ parseLine ( data + '' ) ;
61
+ }
62
+ flushParagraph ( ) ;
63
+ self . emit ( 'end' ) ;
64
+ } ;
65
65
66
66
function resetParagraph ( ) {
67
- is_first_line_in_paragraph = true ;
68
67
paragraph_line_indent = - 1 ;
69
68
70
69
paragraph = {
@@ -165,8 +164,6 @@ function ParagraphParser() {
165
164
166
165
if ( line )
167
166
paragraph . lines . push ( line ) ;
168
-
169
- is_first_line_in_paragraph = false ;
170
167
}
171
168
}
172
169
inherits ( ParagraphParser , Stream ) ;
@@ -185,15 +182,15 @@ function Unwrapper() {
185
182
186
183
this . write = function ( paragraph ) {
187
184
var lines = paragraph . lines ,
188
- break_after = [ ] ,
189
- i ;
185
+ break_after = [ ] ,
186
+ i ;
190
187
191
188
for ( i = 0 ; i < lines . length - 1 ; i ++ ) {
192
189
var line = lines [ i ] ;
193
190
194
191
// When a line is really short, the line was probably kept separate for a
195
192
// reason.
196
- if ( line . length < 50 ) {
193
+ if ( line . length < 50 ) {
197
194
// If the first word on the next line really didn't fit after the line,
198
195
// it probably was just ordinary wrapping after all.
199
196
var next_first_word_length = lines [ i + 1 ] . replace ( / \s .* $ / , '' ) . length ;
@@ -203,7 +200,7 @@ function Unwrapper() {
203
200
}
204
201
}
205
202
206
- for ( i = 0 ; i < lines . length - 1 ; ) {
203
+ for ( i = 0 ; i < lines . length - 1 ; ) {
207
204
if ( ! break_after [ i ] ) {
208
205
lines [ i ] += ' ' + lines . splice ( i + 1 , 1 ) [ 0 ] ;
209
206
} else {
@@ -234,7 +231,7 @@ inherits(Unwrapper, Stream);
234
231
*/
235
232
function RtfGenerator ( ) {
236
233
var self = this ,
237
- did_write_anything = false ;
234
+ did_write_anything = false ;
238
235
239
236
Stream . call ( this ) ;
240
237
this . writable = true ;
@@ -246,10 +243,10 @@ function RtfGenerator() {
246
243
}
247
244
248
245
var li = paragraph . li ,
249
- level = paragraph . level + ( li ? 1 : 0 ) ,
250
- lic = paragraph . in_license_block ;
246
+ level = paragraph . level + ( li ? 1 : 0 ) ,
247
+ lic = paragraph . in_license_block ;
251
248
252
- var rtf = " \\pard" ;
249
+ var rtf = ' \\pard' ;
253
250
rtf += '\\sa150\\sl300\\slmult1' ;
254
251
if ( level > 0 )
255
252
rtf += '\\li' + ( level * 240 ) ;
@@ -290,18 +287,19 @@ function RtfGenerator() {
290
287
function rtfEscape ( string ) {
291
288
return string
292
289
. replace ( / [ \\ \{ \} ] / g, function ( m ) {
293
- return '\\' + m ;
290
+ return '\\' + m ;
294
291
} )
295
292
. replace ( / \t / g, function ( ) {
296
293
return '\\tab ' ;
297
294
} )
295
+ // eslint-disable-next-line no-control-regex
298
296
. replace ( / [ \x00 - \x1f \x7f - \xff ] / g, function ( m ) {
299
297
return '\\\'' + toHex ( m . charCodeAt ( 0 ) , 2 ) ;
300
298
} )
301
299
. replace ( / \ufeff / g, '' )
302
300
. replace ( / [ \u0100 - \uffff ] / g, function ( m ) {
303
301
return '\\u' + toHex ( m . charCodeAt ( 0 ) , 4 ) + '?' ;
304
- } ) ;
302
+ } ) ;
305
303
}
306
304
307
305
function emitHeader ( ) {
@@ -318,11 +316,11 @@ inherits(RtfGenerator, Stream);
318
316
319
317
320
318
var stdin = process . stdin ,
321
- stdout = process . stdout ,
322
- line_splitter = new LineSplitter ( ) ,
323
- paragraph_parser = new ParagraphParser ( ) ,
324
- unwrapper = new Unwrapper ( ) ,
325
- rtf_generator = new RtfGenerator ( ) ;
319
+ stdout = process . stdout ,
320
+ line_splitter = new LineSplitter ( ) ,
321
+ paragraph_parser = new ParagraphParser ( ) ,
322
+ unwrapper = new Unwrapper ( ) ,
323
+ rtf_generator = new RtfGenerator ( ) ;
326
324
327
325
stdin . setEncoding ( 'utf-8' ) ;
328
326
stdin . resume ( ) ;
0 commit comments