@@ -8,6 +8,7 @@ import { DOMParser as dom } from "xmldom";
8
8
const readdir = util . promisify ( fs . readdir ) ;
9
9
const open = util . promisify ( fs . open ) ;
10
10
const readFile = util . promisify ( fs . readFile ) ;
11
+ const errors = [ ] ;
11
12
12
13
// latex (pdf version)
13
14
import {
@@ -157,31 +158,35 @@ async function translateXml(filepath, filename, option) {
157
158
}
158
159
159
160
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"
179
165
) ;
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 ) ;
185
190
}
186
191
return ;
187
192
}
0 commit comments