From a6b98ec628de4e9ae32bdba16e8d4416219de537 Mon Sep 17 00:00:00 2001 From: mattvr <4052466+mattvr@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:34:59 -0700 Subject: [PATCH] fix: broken package / import assertion (#128) --- deno.json | 6 +++--- example/main.ts | 2 +- mod.ts | 14 +++++++++----- test/test.ts | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/deno.json b/deno.json index 60404e9..4c161d1 100644 --- a/deno.json +++ b/deno.json @@ -3,7 +3,7 @@ "version": "0.9.0", "exports": "./mod.ts", "imports": { - "emoji": "jsr:@denosaurs/emoji@0.3", + "emoji": "jsr:@denosaurs/emoji@^0.3", "marked": "npm:marked@^12", "github-slugger": "npm:github-slugger@^2.0", "marked-alert": "npm:marked-alert@^2.0", @@ -11,10 +11,10 @@ "marked-gfm-heading-id": "npm:marked-gfm-heading-id@^3.1", "prismjs": "npm:prismjs@^1.29", "prismjs-yaml": "npm:prismjs@^1.29/components/prism-yaml.js", - "sanitize-html": "npm:sanitize-html@^2.11", + "sanitize-html": "npm:sanitize-html@^2.13", "he": "npm:he@^1.2", "katex": "npm:katex@^0.16", - "@std/assert": "jsr:@std/assert@^0.214" + "@std/assert": "jsr:@std/assert@^1.0" }, "compilerOptions": { "lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"] diff --git a/example/main.ts b/example/main.ts index 2bd341f..b081c93 100644 --- a/example/main.ts +++ b/example/main.ts @@ -53,7 +53,7 @@ async function handler(_req: Request): Promise { }); } catch (err) { console.error(err); - return new Response(err.message, { status: 500 }); + return new Response((err as Error).message, { status: 500 }); } } diff --git a/mod.ts b/mod.ts index 0e40612..93eb18d 100644 --- a/mod.ts +++ b/mod.ts @@ -39,16 +39,20 @@ export class Renderer extends Marked.Renderer { this.#slugger = new GitHubSlugger(); } - heading(text: string, level: 1 | 2 | 3 | 4 | 5 | 6, raw: string): string { + override heading( + text: string, + level: 1 | 2 | 3 | 4 | 5 | 6, + raw: string, + ): string { const slug = this.#slugger.slug(raw); return `${text}\n`; } - image(src: string, title: string | null, alt: string): string { + override image(src: string, title: string | null, alt: string): string { return `${alt}`; } - code(code: string, language?: string): string { + override code(code: string, language?: string): string { const isTitleIncluded = language?.match(/\stitle="(.+)"/); let title = null; if (isTitleIncluded) { @@ -79,7 +83,7 @@ export class Renderer extends Marked.Renderer { return `
${titleHtml}
${html}
`; } - link(href: string, title: string | null, text: string): string { + override link(href: string, title: string | null, text: string): string { const titleAttr = title ? ` title="${title}"` : ""; if (href.startsWith("#")) { return `${text}`; @@ -463,7 +467,7 @@ function stripTokens( } class StripTokenizer extends Marked.Tokenizer { - codespan(src: string): Marked.Tokens.Codespan | undefined { + override codespan(src: string): Marked.Tokens.Codespan | undefined { // copied & modified from Marked to remove escaping const cap = this.rules.inline.code.exec(src); if (cap) { diff --git a/test/test.ts b/test/test.ts index 16837be..1310ac0 100644 --- a/test/test.ts +++ b/test/test.ts @@ -93,7 +93,7 @@ Deno.test("custom renderer", () => { const expected = `

hello world

`; class CustomRenderer extends Renderer { - heading(text: string, level: 1 | 2 | 3 | 4 | 5 | 6): string { + override heading(text: string, level: 1 | 2 | 3 | 4 | 5 | 6): string { return `${text}`; } } @@ -229,7 +229,7 @@ Deno.test("custom allowed classes", async () => { "./test/fixtures/customAllowedClasses.html", ); class CustomRenderer extends Renderer { - list(body: string, ordered: boolean): string { + override list(body: string, ordered: boolean): string { const type = ordered ? "list-decimal" : "list-disc"; const tag = ordered ? "ol" : "ul"; return `<${tag} class="${type}">${body}`;