Skip to content

Commit

Permalink
replace html entities
Browse files Browse the repository at this point in the history
  • Loading branch information
katydecorah committed Jul 14, 2024
1 parent 9207f37 commit 0a002b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/providers/apple-books.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("getAppleBooks", () => {
"categories": [
"Fiction",
],
"description": "<b>This #1 <i>New York Times </i>bestseller is a "bold and subversive retelling of the goddess's story" that brilliantly reimagines the life of Circe, formidable sorceress of The Odyssey (Alexandra Alter, <i>The</i><i>New York Times</i>).</b><br /><br /> In the house of Helios, god of the sun and mi…",
"description": "This #1 is a "bold and subversive retelling of the goddess's story" that brilliantly reimagines the life of Circe, formidable sorceress of The Odyssey (Alexandra Alter, TheNew York Times). In the house of Helios, god of the sun and mi…",
"format": "audiobook",
"identifier": "id1442351802",
"identifiers": {
Expand Down Expand Up @@ -83,7 +83,7 @@ describe("getAppleBooks", () => {
"Literary Fiction",
"Classics",
],
"description": "<b>This #1 <i>New York Times </i>bestseller is a "bold and subversive retelling of the goddess's story" that brilliantly reimagines the life of Circe, formidable sorceress of The Odyssey (Alexandra Alter, <i>The</i><i>New York Times</i>).</b><br /><br /> In the house of Helios, god of the sun and mi…",
"description": "This #1 is a "bold and subversive retelling of the goddess's story" that brilliantly reimagines the life of Circe, formidable sorceress of The Odyssey (Alexandra Alter, TheNew York Times). In the house of Helios, god of the sun and mi…",
"format": "book",
"identifier": "id1442351802",
"identifiers": {
Expand Down Expand Up @@ -134,7 +134,7 @@ describe("getAppleBooks", () => {
{
"authors": [],
"categories": [],
"description": "<b>This #1 <i>New York Times </i>bestseller is a "bold and subversive retelling of the goddess's story" that brilliantly reimagines the life of Circe, formidable sorceress of The Odyssey (Alexandra Alter, <i>The</i><i>New York Times</i>).</b><br /><br /> In the house of Helios, god of the sun and mi…",
"description": "This #1 is a "bold and subversive retelling of the goddess's story" that brilliantly reimagines the life of Circe, formidable sorceress of The Odyssey (Alexandra Alter, TheNew York Times). In the house of Helios, god of the sun and mi…",
"format": "book",
"identifier": "id1442351802",
"identifiers": {
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export function sortByDate(array: NewBook[]): NewBook[] {
export function formatDescription(str?) {
if (!str) return "";

// replace HTML entities
str = str.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
str = str.replace(/&quot;/g, '"');
str = str.replace(/&apos;/g, "'");

// remove HTML tags
str = str.replace(/<\/?[^>]+(>|$)/gm, "");

Expand Down

0 comments on commit 0a002b9

Please sign in to comment.