1
1
import { Chapter , LanguageCode , Manga , MangaStatus , MangaTile , Tag } from "paperback-extensions-common" ;
2
2
3
3
export class CatMangaParser {
4
+
5
+ decodeHTMLEntity ( str : string ) : string {
6
+ return str . replace ( / & # ( \d + ) ; / g, function ( match , dec ) {
7
+ return String . fromCharCode ( dec ) ;
8
+ } )
9
+ }
10
+
4
11
parseTileList ( $ : CheerioStatic , className : string , className2 : string | null = null ) {
5
12
if ( className2 === null ) {
6
13
className2 = className ;
@@ -12,13 +19,13 @@ export class CatMangaParser {
12
19
const tile : MangaTile = {
13
20
id : linkId . replace ( `/series/` , "" ) . split ( "/" ) [ 0 ] ,
14
21
title : createIconText ( {
15
- text : $ ( "p" , element ) . first ( ) . text ( ) . trim ( )
22
+ text : this . decodeHTMLEntity ( $ ( "p" , element ) . first ( ) . text ( ) . trim ( ) )
16
23
} ) ,
17
24
image : $ ( "img" , element ) . attr ( "src" ) || ""
18
25
}
19
26
if ( $ ( "p" , element ) . length > 1 ) {
20
27
tile . primaryText = createIconText ( {
21
- text : $ ( "p" , element ) . last ( ) . text ( ) . trim ( )
28
+ text : this . decodeHTMLEntity ( $ ( "p" , element ) . last ( ) . text ( ) . trim ( ) )
22
29
} ) ;
23
30
}
24
31
mangaTiles . push ( createMangaTile ( tile ) ) ;
@@ -40,11 +47,11 @@ export class CatMangaParser {
40
47
mangaTiles . push ( createMangaTile ( {
41
48
id : id ,
42
49
title : createIconText ( {
43
- text : $ ( "h1" , element ) . first ( ) . text ( ) . trim ( )
50
+ text : this . decodeHTMLEntity ( $ ( "h1" , element ) . first ( ) . text ( ) . trim ( ) )
44
51
} ) ,
45
52
image : base + $ ( "img" , element ) . attr ( "src" ) || "" ,
46
53
primaryText : createIconText ( {
47
- text : $ ( "div p" , $ ( "a" , element ) . parent ( ) ) . first ( ) . text ( ) . trim ( )
54
+ text : this . decodeHTMLEntity ( $ ( "div p" , $ ( "a" , element ) . parent ( ) ) . first ( ) . text ( ) . trim ( ) )
48
55
} )
49
56
} ) )
50
57
}
@@ -88,7 +95,7 @@ export class CatMangaParser {
88
95
id : String ( chapter . number ) ,
89
96
langCode : LanguageCode . ENGLISH ,
90
97
mangaId : mangaId ,
91
- name : chapter . title ,
98
+ name : this . decodeHTMLEntity ( chapter . title ) ,
92
99
group : ( chapter . groups || [ ] ) . join ( ", " )
93
100
} ) ) }
94
101
}
@@ -109,14 +116,14 @@ export class CatMangaParser {
109
116
const chapNum = Number ( chapNumString ) || 0 ;
110
117
let title : string | null = null ;
111
118
if ( chapNum === 0 ) {
112
- title = chapNumString
119
+ title = chapNumString ;
113
120
}
114
121
const data : Chapter = {
115
122
chapNum : chapNum ,
116
123
id : String ( chapNum ) ,
117
124
langCode : LanguageCode . ENGLISH ,
118
125
mangaId : mangaId ,
119
- name : title || $ ( "p" , element ) . last ( ) . text ( ) . trim ( )
126
+ name : this . decodeHTMLEntity ( title || $ ( "p" , element ) . last ( ) . text ( ) . trim ( ) )
120
127
} ;
121
128
chapters . push ( createChapter ( data ) ) ;
122
129
} )
@@ -157,10 +164,16 @@ export class CatMangaParser {
157
164
label : tag
158
165
} ) )
159
166
}
167
+ for ( let i = 0 ; i < series . authors . length ; i ++ ) {
168
+ series . authors [ i ] = this . decodeHTMLEntity ( series . authors [ i ] ) ;
169
+ }
170
+ for ( let i = 0 ; i < titles . length ; i ++ ) {
171
+ titles [ i ] = this . decodeHTMLEntity ( titles [ i ] ) ;
172
+ }
160
173
return createManga ( {
161
174
author : ( series . authors || [ ] ) . join ( ", " ) ,
162
175
covers : covers ,
163
- desc : series . description ,
176
+ desc : this . decodeHTMLEntity ( series . description ) ,
164
177
id : mangaId ,
165
178
image : series . cover_art . source ,
166
179
rating : 0 ,
@@ -195,12 +208,12 @@ export class CatMangaParser {
195
208
status = MangaStatus . COMPLETED ;
196
209
}
197
210
const mangaObj : Manga = {
198
- desc : $ ( 'div[class^="series_seriesDesc"]' ) . first ( ) . text ( ) . trim ( ) ,
211
+ desc : this . decodeHTMLEntity ( $ ( 'div[class^="series_seriesDesc"]' ) . first ( ) . text ( ) . trim ( ) ) ,
199
212
id : mangaId ,
200
213
image : $ ( "img" ) . attr ( "src" ) || "" ,
201
214
rating : 0 ,
202
215
status : status ,
203
- titles : [ $ ( "h1" ) . first ( ) . text ( ) ] ,
216
+ titles : [ this . decodeHTMLEntity ( $ ( "h1" ) . first ( ) . text ( ) ) ] ,
204
217
tags : [ createTagSection ( {
205
218
id : "tags" ,
206
219
label : "Tags" ,
0 commit comments