Skip to content

Commit 82304c1

Browse files
committed
Adds a html decoder
1 parent dadb4fb commit 82304c1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/xd-crossword-tools/src/amuseJSONToXD.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { JSONToXD } from "./JSONtoXD"
22
import type { Clue, Position as CluePosition, CrosswordJSON, Report } from "xd-crossword-tools-parser"
33

44
import type { CellInfo, PlacedWord, AmuseTopLevel } from "./amuseJSONToXD.types.d.ts"
5-
import { doesNotReject } from "assert"
65

76
/** Convert an Amuse JSON to an XD file. */
87
export const amuseToXD = (amuseJSON: AmuseTopLevel) => JSONToXD(convertAmuseToCrosswordJSON(amuseJSON))
@@ -429,9 +428,16 @@ export function convertHtmlToXdMarkup(html: string | undefined): string {
429428
)
430429
}
431430

431+
// Don't think this is actually a goal: https://github.com/puzzmo-com/xd-crossword-tools/issues/46
432+
// Convert spaced dots to ellipsis
433+
// result = result.replace(/\. \. \./g, "…")
434+
432435
// Clean up excessive whitespace and newlines
433436
result = result.replace(/\n+/g, "\n").trim()
434437

438+
// Remove extra HTML entities like "'"
439+
result = result.replace(/&#(\d+);/g, (match, dec) => String.fromCharCode(dec))
440+
435441
return result
436442
}
437443

packages/xd-crossword-tools/tests/amuseJSONToXD.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const shouldRunTests = existsSync(fullExamplePath) && existsSync(hasCirclesPath)
1616

1717
const describeConditional = shouldRunTests ? describe : describe.skip
1818

19-
describe("amuseJSONToXD", () => {
19+
describeConditional("amuseJSONToXD", () => {
2020
it("handles schrodinger clues correctly", () => {
2121
const result = convertAmuseToCrosswordJSON(schrodingerAmuseExample)
2222

@@ -202,6 +202,13 @@ describe("amuseJSONToXD", () => {
202202
})
203203
})
204204

205+
it.skip("handles converting ellipsis", () => {
206+
const result = convertAmuseToCrosswordJSON(amuseJSON)
207+
208+
const across7 = result.clues.across.find((clue) => clue.number === 7)
209+
expect(across7?.body).toMatchInlineSnapshot(`"Single ensign full of exuberance … (4)"`)
210+
})
211+
205212
describe("amuseToXD", () => {
206213
it("converts amuse JSON to XD string format", () => {
207214
const result = amuseToXD(amuseJSON)

0 commit comments

Comments
 (0)