@@ -94,7 +94,7 @@ function parseEntries(rawText) {
9494
9595 const term = line . slice ( 0 , firstComma ) . trim ( ) ;
9696 const reading = line . slice ( firstComma + 1 , secondComma ) . trim ( ) ;
97- const definition = line . slice ( secondComma + 1 ) . trim ( ) ;
97+ const definition = line . slice ( secondComma + 1 ) . trim ( ) . replace ( / \\ n / g , "\n" ) ;
9898 if ( ! term ) continue ;
9999 entries . push ( { term, reading, definition } ) ;
100100 }
@@ -121,9 +121,21 @@ async function buildZip(dictName, entries) {
121121 for ( let i = 0 ; i < entries . length ; i += TERM_LIMIT ) {
122122 const chunk = entries . slice ( i , i + TERM_LIMIT ) ;
123123 const bankIndex = Math . floor ( i / TERM_LIMIT ) + 1 ;
124- const bank = chunk . map ( ( { term, reading, definition } ) =>
125- [ term , reading , TAG_NAME , "" , 0 , [ definition ] , 0 , "" ]
126- ) ;
124+ const bank = chunk . map ( ( { term, reading, definition } ) => {
125+ let defEntry ;
126+ if ( definition . includes ( "\n" ) ) {
127+ const parts = definition . split ( "\n" ) ;
128+ const content = [ ] ;
129+ parts . forEach ( ( part , i ) => {
130+ if ( i > 0 ) content . push ( { tag : "br" } ) ;
131+ content . push ( part ) ;
132+ } ) ;
133+ defEntry = [ { type : "structured-content" , content } ] ;
134+ } else {
135+ defEntry = [ definition ] ;
136+ }
137+ return [ term , reading , TAG_NAME , "" , 0 , defEntry , 0 , "" ] ;
138+ } ) ;
127139 zip . file ( `term_bank_${ bankIndex } .json` , JSON . stringify ( bank ) ) ;
128140 }
129141
@@ -177,7 +189,19 @@ async function parseZip(file) {
177189 const term = entry [ 0 ] ?? "" ;
178190 const reading = entry [ 1 ] ?? "" ;
179191 const defs = entry [ 5 ] ;
180- const definition = Array . isArray ( defs ) ? defs . join ( " / " ) : ( defs ?? "" ) ;
192+ const definition = Array . isArray ( defs )
193+ ? defs . map ( d => {
194+ if ( typeof d === "string" ) return d ;
195+ if ( d && d . type === "structured-content" && Array . isArray ( d . content ) ) {
196+ return d . content . map ( p => {
197+ if ( typeof p === "string" ) return p ;
198+ if ( p && p . tag === "br" ) return "\\n" ;
199+ return "" ;
200+ } ) . join ( "" ) ;
201+ }
202+ return String ( d ?? "" ) ;
203+ } ) . join ( " / " )
204+ : ( defs ?? "" ) ;
181205 lines . push ( `${ term } , ${ reading } , ${ definition } ` ) ;
182206 }
183207 }
0 commit comments