@@ -8,6 +8,7 @@ import { DOMParser as dom } from "xmldom";
88const readdir = util . promisify ( fs . readdir ) ;
99const open = util . promisify ( fs . open ) ;
1010const readFile = util . promisify ( fs . readFile ) ;
11+ const errors = [ ] ;
1112
1213// latex (pdf version)
1314import {
@@ -157,31 +158,35 @@ async function translateXml(filepath, filename, option) {
157158 }
158159
159160 if ( parseType == "json" ) {
160- const relativeFilePath = path . join (
161- filepath ,
162- filename . replace ( / \. x m l $ / , "" ) + ".html"
163- ) ;
164-
165- if ( option == "generateTOC" ) {
166- generateTOC ( doc , tableOfContent , relativeFilePath ) ;
167- return ;
168- } else if ( option == "setupSnippet" ) {
169- setupSnippetsJson ( doc . documentElement ) ;
170- setupReferencesJson ( doc . documentElement , relativeFilePath ) ;
171- return ;
172- } else if ( option == "parseXml" ) {
173- const jsonObj = [ ] ;
174- parseXmlJson ( doc , jsonObj , relativeFilePath ) ;
175-
176- const outputFile = path . join (
177- outputDir ,
178- tableOfContent [ relativeFilePath ] . index + ".json"
161+ try {
162+ const relativeFilePath = path . join (
163+ filepath ,
164+ filename . replace ( / \. x m l $ / , "" ) + ".html"
179165 ) ;
180- const stream = fs . createWriteStream ( outputFile ) ;
181- stream . once ( "open" , fd => {
182- stream . write ( JSON . stringify ( jsonObj ) ) ;
183- stream . end ( ) ;
184- } ) ;
166+
167+ if ( option == "generateTOC" ) {
168+ generateTOC ( doc , tableOfContent , relativeFilePath ) ;
169+ return ;
170+ } else if ( option == "setupSnippet" ) {
171+ setupSnippetsJson ( doc . documentElement ) ;
172+ setupReferencesJson ( doc . documentElement , relativeFilePath ) ;
173+ return ;
174+ } else if ( option == "parseXml" ) {
175+ const jsonObj = [ ] ;
176+ parseXmlJson ( doc , jsonObj , relativeFilePath ) ;
177+
178+ const outputFile = path . join (
179+ outputDir ,
180+ tableOfContent [ relativeFilePath ] . index + ".json"
181+ ) ;
182+ const stream = fs . createWriteStream ( outputFile ) ;
183+ stream . once ( "open" , fd => {
184+ stream . write ( JSON . stringify ( jsonObj ) ) ;
185+ stream . end ( ) ;
186+ } ) ;
187+ }
188+ } catch ( error ) {
189+ errors . push ( path . join ( filepath , filename ) + " " + error ) ;
185190 }
186191 return ;
187192 }
0 commit comments