11import { Chapter , LanguageCode , Manga , MangaStatus , MangaTile , Tag } from "paperback-extensions-common" ;
22
33export 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+
411parseTileList ( $ :CheerioStatic , className :string , className2 :string | null = null ) {
512if ( className2 === null ) {
613className2 = className ;
@@ -12,13 +19,13 @@ export class CatMangaParser {
1219const tile :MangaTile = {
1320id :linkId . replace ( `/series/` , "" ) . split ( "/" ) [ 0 ] ,
1421title :createIconText ( {
15- text :$ ( "p" , element ) . first ( ) . text ( ) . trim ( )
22+ text :this . decodeHTMLEntity ( $ ( "p" , element ) . first ( ) . text ( ) . trim ( ) )
1623} ) ,
1724image :$ ( "img" , element ) . attr ( "src" ) || ""
1825}
1926if ( $ ( "p" , element ) . length > 1 ) {
2027tile . primaryText = createIconText ( {
21- text :$ ( "p" , element ) . last ( ) . text ( ) . trim ( )
28+ text :this . decodeHTMLEntity ( $ ( "p" , element ) . last ( ) . text ( ) . trim ( ) )
2229} ) ;
2330}
2431mangaTiles . push ( createMangaTile ( tile ) ) ;
@@ -40,11 +47,11 @@ export class CatMangaParser {
4047mangaTiles . push ( createMangaTile ( {
4148id :id ,
4249title :createIconText ( {
43- text :$ ( "h1" , element ) . first ( ) . text ( ) . trim ( )
50+ text :this . decodeHTMLEntity ( $ ( "h1" , element ) . first ( ) . text ( ) . trim ( ) )
4451} ) ,
4552image :base + $ ( "img" , element ) . attr ( "src" ) || "" ,
4653primaryText :createIconText ( {
47- text :$ ( "div p" , $ ( "a" , element ) . parent ( ) ) . first ( ) . text ( ) . trim ( )
54+ text :this . decodeHTMLEntity ( $ ( "div p" , $ ( "a" , element ) . parent ( ) ) . first ( ) . text ( ) . trim ( ) )
4855} )
4956} ) )
5057}
@@ -88,7 +95,7 @@ export class CatMangaParser {
8895id :String ( chapter . number ) ,
8996langCode :LanguageCode . ENGLISH ,
9097mangaId :mangaId ,
91- name :chapter . title ,
98+ name :this . decodeHTMLEntity ( chapter . title ) ,
9299group :( chapter . groups || [ ] ) . join ( ", " )
93100} ) ) }
94101}
@@ -109,14 +116,14 @@ export class CatMangaParser {
109116const chapNum = Number ( chapNumString ) || 0 ;
110117let title :string | null = null ;
111118if ( chapNum === 0 ) {
112- title = chapNumString
119+ title = chapNumString ;
113120}
114121const data :Chapter = {
115122chapNum :chapNum ,
116123id :String ( chapNum ) ,
117124langCode :LanguageCode . ENGLISH ,
118125mangaId :mangaId ,
119- name :title || $ ( "p" , element ) . last ( ) . text ( ) . trim ( )
126+ name :this . decodeHTMLEntity ( title || $ ( "p" , element ) . last ( ) . text ( ) . trim ( ) )
120127} ;
121128chapters . push ( createChapter ( data ) ) ;
122129} )
@@ -157,10 +164,16 @@ export class CatMangaParser {
157164label :tag
158165} ) )
159166}
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+ }
160173return createManga ( {
161174author :( series . authors || [ ] ) . join ( ", " ) ,
162175covers :covers ,
163- desc :series . description ,
176+ desc :this . decodeHTMLEntity ( series . description ) ,
164177id :mangaId ,
165178image :series . cover_art . source ,
166179rating :0 ,
@@ -195,12 +208,12 @@ export class CatMangaParser {
195208status = MangaStatus . COMPLETED ;
196209}
197210const mangaObj :Manga = {
198- desc :$ ( 'div[class^="series_seriesDesc"]' ) . first ( ) . text ( ) . trim ( ) ,
211+ desc :this . decodeHTMLEntity ( $ ( 'div[class^="series_seriesDesc"]' ) . first ( ) . text ( ) . trim ( ) ) ,
199212id :mangaId ,
200213image :$ ( "img" ) . attr ( "src" ) || "" ,
201214rating :0 ,
202215status :status ,
203- titles :[ $ ( "h1" ) . first ( ) . text ( ) ] ,
216+ titles :[ this . decodeHTMLEntity ( $ ( "h1" ) . first ( ) . text ( ) ) ] ,
204217tags :[ createTagSection ( {
205218id :"tags" ,
206219label :"Tags" ,