@@ -21,6 +21,8 @@ const CommonMarkTransformer = require('@accordproject/markdown-common').CommonMa
2121const CiceroMarkTransformer = require ( '@accordproject/markdown-cicero' ) . CiceroMarkTransformer ;
2222const SlateTransformer = require ( '@accordproject/markdown-slate' ) . SlateTransformer ;
2323const HtmlTransformer = require ( '@accordproject/markdown-html' ) . HtmlTransformer ;
24+ const PdfTransformer = require ( '@accordproject/markdown-pdf' ) . PdfTransformer ;
25+ const DocxTransformer = require ( '@accordproject/markdown-docx' ) . DocxTransformer ;
2426
2527/**
2628 * Utility class that implements the commands exposed by the CLI.
@@ -62,7 +64,7 @@ class Commands {
6264 argv = Commands . setDefaultFileArg ( argv , 'sample' , 'sample.md' , ( ( argv , argDefaultName ) => { return argDefaultName ; } ) ) ;
6365
6466 if ( argv . verbose ) {
65- Logger . info ( `parse sample ${ argv . sample } printing intermediate transformations.` ) ;
67+ Logger . info ( `parse sample ${ argv . sample } (or docx, pdf) printing intermediate transformations.` ) ;
6668 }
6769
6870 return argv ;
@@ -80,7 +82,7 @@ class Commands {
8082 * @param {boolean } [options.verbose] verbose output
8183 * @returns {object } Promise to the result of parsing
8284 */
83- static parse ( samplePath , outputPath , options ) {
85+ static async parse ( samplePath , outputPath , options ) {
8486 const { cicero, slate, html, verbose } = options ;
8587 const commonOptions = { } ;
8688 commonOptions . tagInfo = true ;
@@ -89,9 +91,24 @@ class Commands {
8991 const ciceroMark = new CiceroMarkTransformer ( ) ;
9092 const slateMark = new SlateTransformer ( ) ;
9193 const htmlMark = new HtmlTransformer ( ) ;
94+ const docx = new DocxTransformer ( ) ;
95+ const pdf = new PdfTransformer ( ) ;
96+
97+ let result = null ;
98+
99+ if ( samplePath . endsWith ( '.pdf' ) ) {
100+ const pdfBuffer = Fs . readFileSync ( samplePath ) ;
101+ result = await pdf . toCiceroMark ( pdfBuffer , 'json' ) ;
102+ }
103+ else if ( samplePath . endsWith ( '.docx' ) ) {
104+ const docxBuffer = Fs . readFileSync ( samplePath ) ;
105+ result = await docx . toCiceroMark ( docxBuffer , 'json' ) ;
106+ }
107+ else {
108+ const markdownText = Fs . readFileSync ( samplePath , 'utf8' ) ;
109+ result = commonMark . fromMarkdown ( markdownText , 'json' ) ;
110+ }
92111
93- const markdownText = Fs . readFileSync ( samplePath , 'utf8' ) ;
94- let result = commonMark . fromMarkdown ( markdownText , 'json' ) ;
95112 if ( verbose ) {
96113 Logger . info ( '=== CommonMark ===' ) ;
97114 Logger . info ( JSON . stringify ( result , null , 4 ) ) ;
@@ -150,7 +167,7 @@ class Commands {
150167 }
151168
152169 /**
153- * Parse a sample markdown
170+ * Parse a sample markdown/pdf/docx
154171 *
155172 * @param {string } dataPath to the sample file
156173 * @param {string } outputPath to an output file
0 commit comments