Closed rgembalik closed 2 years ago
Alright, I did it, so, if anyone else stumbles on this, here's how I am doing it:
const decoder = new TextDecoder("utf-8");
decodeEntities(game.description) // Not native, you need to find your own implementation - it will parse initial `&` to build actual entities.
.replace(/(&#(\d+);)+/gi, (result) => // any sequence of `&#xxx;&#yyy;` entities
decoder.decode( // is transformed into new Uint8Array([xxx, yyy]) and pushed through decoder
new Uint8Array(
result
.match(/&#(\d+);/gi)
.map((e) => e.replace(/&#(\d+);/gi, (_, code) => code))
.map((num) => parseInt(num))
)
)
)
.split("\n") // finally, newline characters
.filter((v) => v !== "")
.map((v) => `<p>${v}</p>`) // are replaced with paragraphs wrapping entire line
.join("\n")
I am trying to parse the description response; in many cases, it contains HTML entities (or so it seems). However, those do not seem to play well directly used as such. Take for example https://api.geekdo.com/xmlapi2/thing?id=40834&versions=1
Does anyone have any idea how to use it to display the correct description in HTML? I cannot seem to wrap my head around it.
Raw description
`In Dominion: Intrigue (as with Dominion), each player starts with an identical, very small deck of cards. In the center of the table is a selection of other cards the players can "buy" as they can afford them. Through their selection of cards to buy, and how they play their hands as they draw them, the players construct their deck on the fly, striving for the most efficient path to the precious victory points by game end. From the back of the box: "Something’s afoot. The steward smiles at you like he has a secret, or like he thinks you have a secret, or like you think he thinks you have a secret. There are secret plots brewing, you’re sure of it. At the very least, there are yours. A passing servant murmurs, “The eggs are on the plate.” You frantically search your codebook for the translation before realizing he means that breakfast is ready. Excellent. Everything is going according to plan." Dominion: Intrigue adds rules for playing with up to 8 players at two tables or for playing a single game with up to 6 players when combined with Dominion. This game adds 25 new Kingdom cards and a complete set of Treasure and Victory cards. The game can be played alone by players experienced in Dominion or with the basic game of Dominion. Part of the Dominion series. Integrates with: Dominion Also released as an expansion that requires the base game or card set to play: Dominion: Die Intrige – Erweiterung. `