@@ -13,7 +13,13 @@ import {
1313 OSFValue ,
1414 TextRun ,
1515} from 'omniscript-parser' ;
16- import { PDFConverter , DOCXConverter , PPTXConverter , XLSXConverter } from 'omniscript-converters' ;
16+ import {
17+ PDFConverter ,
18+ DOCXConverter ,
19+ PPTXConverter ,
20+ XLSXConverter ,
21+ ConverterOptions ,
22+ } from 'omniscript-converters' ;
1723
1824// Type definitions for formula handling
1925interface FormulaDefinition {
@@ -27,6 +33,15 @@ type CellValue = string | number | boolean;
2733// Type for spreadsheet data
2834type SpreadsheetData = Record < string , CellValue > ;
2935
36+ // Type for styled text with optional formatting
37+ interface StyledText {
38+ text : string ;
39+ bold ?: boolean ;
40+ italic ?: boolean ;
41+ underline ?: boolean ;
42+ strike ?: boolean ;
43+ }
44+
3045// Helper function to render TextRun to HTML
3146function renderTextRun ( run : TextRun ) : string {
3247 if ( typeof run === 'string' ) {
@@ -42,10 +57,11 @@ function renderTextRun(run: TextRun): string {
4257 }
4358 if ( 'text' in run ) {
4459 let text = escapeHtml ( run . text ) ;
45- if ( ( run as any ) . bold ) text = `<strong>${ text } </strong>` ;
46- if ( ( run as any ) . italic ) text = `<em>${ text } </em>` ;
47- if ( ( run as any ) . underline ) text = `<u>${ text } </u>` ;
48- if ( ( run as any ) . strike ) text = `<s>${ text } </s>` ;
60+ const styledRun = run as StyledText ;
61+ if ( styledRun . bold ) text = `<strong>${ text } </strong>` ;
62+ if ( styledRun . italic ) text = `<em>${ text } </em>` ;
63+ if ( styledRun . underline ) text = `<u>${ text } </u>` ;
64+ if ( styledRun . strike ) text = `<s>${ text } </s>` ;
4965 return text ;
5066 }
5167 return '' ;
@@ -592,25 +608,25 @@ function renderHtml(doc: OSFDocument): string {
592608}
593609
594610// Advanced format renderers using omniscript-converters
595- async function renderPdf ( doc : OSFDocument , options ?: any ) : Promise < Buffer > {
611+ async function renderPdf ( doc : OSFDocument , options ?: ConverterOptions ) : Promise < Buffer > {
596612 const converter = new PDFConverter ( ) ;
597613 const result = await converter . convert ( doc , options || { } ) ;
598614 return result . buffer ;
599615}
600616
601- async function renderDocx ( doc : OSFDocument , options ?: any ) : Promise < Buffer > {
617+ async function renderDocx ( doc : OSFDocument , options ?: ConverterOptions ) : Promise < Buffer > {
602618 const converter = new DOCXConverter ( ) ;
603619 const result = await converter . convert ( doc , options || { } ) ;
604620 return result . buffer ;
605621}
606622
607- async function renderPptx ( doc : OSFDocument , options ?: any ) : Promise < Buffer > {
623+ async function renderPptx ( doc : OSFDocument , options ?: ConverterOptions ) : Promise < Buffer > {
608624 const converter = new PPTXConverter ( ) ;
609625 const result = await converter . convert ( doc , options || { } ) ;
610626 return result . buffer ;
611627}
612628
613- async function renderXlsx ( doc : OSFDocument , options ?: any ) : Promise < Buffer > {
629+ async function renderXlsx ( doc : OSFDocument , options ?: ConverterOptions ) : Promise < Buffer > {
614630 const converter = new XLSXConverter ( ) ;
615631 const result = await converter . convert ( doc , options || { } ) ;
616632 return result . buffer ;
@@ -631,10 +647,11 @@ function textRunToMarkdown(run: TextRun): string {
631647 }
632648 if ( 'text' in run ) {
633649 let text = run . text ;
634- if ( ( run as any ) . bold ) text = `**${ text } **` ;
635- if ( ( run as any ) . italic ) text = `*${ text } *` ;
636- if ( ( run as any ) . underline ) text = `__${ text } __` ;
637- if ( ( run as any ) . strike ) text = `~~${ text } ~~` ;
650+ const styledRun = run as StyledText ;
651+ if ( styledRun . bold ) text = `**${ text } **` ;
652+ if ( styledRun . italic ) text = `*${ text } *` ;
653+ if ( styledRun . underline ) text = `__${ text } __` ;
654+ if ( styledRun . strike ) text = `~~${ text } ~~` ;
638655 return text ;
639656 }
640657 return '' ;
@@ -1018,7 +1035,7 @@ async function main(): Promise<void> {
10181035 break ;
10191036 }
10201037 case 'pdf' : {
1021- const pdfBuffer = await renderPdf ( doc , { theme } ) ;
1038+ const pdfBuffer = await renderPdf ( doc , { theme } as ConverterOptions ) ;
10221039 if ( outputFile ) {
10231040 writeFileSync ( outputFile , pdfBuffer ) ;
10241041 console . log ( `PDF written to ${ outputFile } ` ) ;
@@ -1028,7 +1045,7 @@ async function main(): Promise<void> {
10281045 break ;
10291046 }
10301047 case 'docx' : {
1031- const docxBuffer = await renderDocx ( doc , { theme } ) ;
1048+ const docxBuffer = await renderDocx ( doc , { theme } as ConverterOptions ) ;
10321049 if ( outputFile ) {
10331050 writeFileSync ( outputFile , docxBuffer ) ;
10341051 console . log ( `DOCX written to ${ outputFile } ` ) ;
@@ -1038,7 +1055,7 @@ async function main(): Promise<void> {
10381055 break ;
10391056 }
10401057 case 'pptx' : {
1041- const pptxBuffer = await renderPptx ( doc , { theme } ) ;
1058+ const pptxBuffer = await renderPptx ( doc , { theme } as ConverterOptions ) ;
10421059 if ( outputFile ) {
10431060 writeFileSync ( outputFile , pptxBuffer ) ;
10441061 console . log ( `PPTX written to ${ outputFile } ` ) ;
@@ -1048,7 +1065,7 @@ async function main(): Promise<void> {
10481065 break ;
10491066 }
10501067 case 'xlsx' : {
1051- const xlsxBuffer = await renderXlsx ( doc , { theme } ) ;
1068+ const xlsxBuffer = await renderXlsx ( doc , { theme } as ConverterOptions ) ;
10521069 if ( outputFile ) {
10531070 writeFileSync ( outputFile , xlsxBuffer ) ;
10541071 console . log ( `XLSX written to ${ outputFile } ` ) ;
0 commit comments