@@ -130,13 +130,13 @@ namespace Word {
130130 }
131131}
132132
133- var sys = ( function ( ) {
134- var fileStream = new ActiveXObject ( "ADODB.Stream" ) ;
135- fileStream . Type = 2 /*text*/ ;
136- var binaryStream = new ActiveXObject ( "ADODB.Stream" ) ;
137- binaryStream . Type = 1 /*binary*/ ;
138- var args : string [ ] = [ ] ;
139- for ( var i = 0 ; i < WScript . Arguments . length ; i ++ ) {
133+ const sys = ( function ( ) {
134+ const fileStream = new ActiveXObject ( "ADODB.Stream" ) ;
135+ fileStream . Type = 2 /* text */ ;
136+ const binaryStream = new ActiveXObject ( "ADODB.Stream" ) ;
137+ binaryStream . Type = 1 /* binary */ ;
138+ const args : string [ ] = [ ] ;
139+ for ( let i = 0 ; i < WScript . Arguments . length ; i ++ ) {
140140 args [ i ] = WScript . Arguments . Item ( i ) ;
141141 }
142142 return {
@@ -176,17 +176,17 @@ interface FindReplaceOptions {
176176
177177function convertDocumentToMarkdown ( doc : Word . Document ) : string {
178178
179- var result = "" ;
180- var lastStyle : string ;
181- var lastInTable : boolean ;
182- var tableColumnCount : number ;
183- var tableCellIndex : number ;
184- var columnAlignment : number [ ] = [ ] ;
179+ const columnAlignment : number [ ] = [ ] ;
180+ let tableColumnCount : number ;
181+ let tableCellIndex : number ;
182+ let lastInTable : boolean ;
183+ let lastStyle : string ;
184+ let result = "" ;
185185
186186 function setProperties ( target : any , properties : any ) {
187- for ( var name in properties ) {
187+ for ( const name in properties ) {
188188 if ( properties . hasOwnProperty ( name ) ) {
189- var value = properties [ name ] ;
189+ const value = properties [ name ] ;
190190 if ( typeof value === "object" ) {
191191 setProperties ( target [ name ] , value ) ;
192192 }
@@ -198,10 +198,10 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
198198 }
199199
200200 function findReplace ( findText : string , findOptions : FindReplaceOptions , replaceText : string , replaceOptions : FindReplaceOptions ) {
201- var find = doc . range ( ) . find ;
201+ const find = doc . range ( ) . find ;
202202 find . clearFormatting ( ) ;
203203 setProperties ( find , findOptions ) ;
204- var replace = find . replacement ;
204+ const replace = find . replacement ;
205205 replace . clearFormatting ( ) ;
206206 setProperties ( replace , replaceOptions ) ;
207207 find . execute ( findText ,
@@ -219,12 +219,12 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
219219 }
220220
221221 function fixHyperlinks ( ) {
222- var count = doc . hyperlinks . count ;
223- for ( var i = 0 ; i < count ; i ++ ) {
224- var hyperlink = doc . hyperlinks . item ( i + 1 ) ;
225- var address = hyperlink . address ;
222+ const count = doc . hyperlinks . count ;
223+ for ( let i = 0 ; i < count ; i ++ ) {
224+ const hyperlink = doc . hyperlinks . item ( i + 1 ) ;
225+ const address = hyperlink . address ;
226226 if ( address && address . length > 0 ) {
227- var textToDisplay = hyperlink . textToDisplay ;
227+ const textToDisplay = hyperlink . textToDisplay ;
228228 hyperlink . textToDisplay = "[" + textToDisplay + "](" + address + ")" ;
229229 }
230230 }
@@ -235,7 +235,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
235235 }
236236
237237 function writeTableHeader ( ) {
238- for ( var i = 0 ; i < tableColumnCount - 1 ; i ++ ) {
238+ for ( let i = 0 ; i < tableColumnCount - 1 ; i ++ ) {
239239 switch ( columnAlignment [ i ] ) {
240240 case 1 :
241241 write ( "|:---:" ) ;
@@ -251,7 +251,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
251251 }
252252
253253 function trimEndFormattingMarks ( text : string ) {
254- var i = text . length ;
254+ let i = text . length ;
255255 while ( i > 0 && text . charCodeAt ( i - 1 ) < 0x20 ) i -- ;
256256 return text . substr ( 0 , i ) ;
257257 }
@@ -271,12 +271,13 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
271271
272272 function writeParagraph ( p : Word . Paragraph ) {
273273
274- var range = p . range ;
275- var text = range . text ;
276- var style = p . style . nameLocal ;
277- var inTable = range . tables . count > 0 ;
278- var level = 1 ;
279- var sectionBreak = text . indexOf ( "\x0C" ) >= 0 ;
274+ const range = p . range ;
275+ const inTable = range . tables . count > 0 ;
276+ const sectionBreak = range . text . indexOf ( "\x0C" ) >= 0 ;
277+
278+ let level = 1 ;
279+ let style = p . style . nameLocal ;
280+ let text = range . text ;
280281
281282 text = trimEndFormattingMarks ( text ) ;
282283 if ( text === "/" ) {
@@ -285,7 +286,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
285286 // hidden text and, if so, emit that instead. The hidden text is assumed to
286287 // contain an appropriate markdown image link.
287288 range . textRetrievalMode . includeHiddenText = true ;
288- var fullText = range . text ;
289+ const fullText = range . text ;
289290 range . textRetrievalMode . includeHiddenText = false ;
290291 if ( text !== fullText ) {
291292 text = "  " + fullText . substr ( 1 ) ;
@@ -307,7 +308,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
307308
308309 case "Heading" :
309310 case "Appendix" :
310- var section = range . listFormat . listString ;
311+ const section = range . listFormat . listString ;
311312 write ( "####" . substr ( 0 , level ) + ' <a name="' + section + '"/>' + section + " " + text + "\n\n" ) ;
312313 break ;
313314
@@ -358,7 +359,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
358359 break ;
359360
360361 case "TOC" :
361- var strings = text . split ( "\t" ) ;
362+ const strings = text . split ( "\t" ) ;
362363 write ( " " . substr ( 0 , level * 2 - 2 ) + "* [" + strings [ 0 ] + " " + strings [ 1 ] + "](#" + strings [ 0 ] + ")\n" ) ;
363364 break ;
364365 }
@@ -371,11 +372,11 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
371372 }
372373
373374 function writeDocument ( ) {
374- var title = doc . builtInDocumentProperties . item ( 1 ) + "" ;
375+ const title = doc . builtInDocumentProperties . item ( 1 ) + "" ;
375376 if ( title . length ) {
376377 write ( "# " + title + "\n\n" ) ;
377378 }
378- for ( var p = doc . paragraphs . first ; p ; p = p . next ( ) ) {
379+ for ( let p = doc . paragraphs . first ; p ; p = p . next ( ) ) {
379380 writeParagraph ( p ) ;
380381 }
381382 writeBlockEnd ( ) ;
@@ -412,8 +413,8 @@ function main(args: string[]) {
412413 sys . write ( "Syntax: word2md <inputfile> <outputfile>\n" ) ;
413414 return ;
414415 }
415- var app : Word . Application = sys . createObject ( "Word.Application" ) ;
416- var doc = app . documents . open ( args [ 0 ] ) ;
416+ const app : Word . Application = sys . createObject ( "Word.Application" ) ;
417+ const doc = app . documents . open ( args [ 0 ] ) ;
417418 sys . writeFile ( args [ 1 ] , convertDocumentToMarkdown ( doc ) ) ;
418419 doc . close ( /* saveChanges */ false ) ;
419420 app . quit ( ) ;
0 commit comments