Skip to content
This repository was archived by the owner on Nov 20, 2021. It is now read-only.

Commit 71b9d7e

Browse files
committed
Fix HTML Entities (Fix #2)
1 parent b567eec commit 71b9d7e

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

Diff for: src/CatManga/CatMangaParser.ts

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import {Chapter, LanguageCode, Manga, MangaStatus, MangaTile, Tag} from "paperback-extensions-common";
22

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

0 commit comments

Comments
 (0)