marked: Fix type stub to declare marked as a CommonJS module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-06-08 00:17:35 -07:00
parent 858bcca713
commit 13c44efad9
2 changed files with 82 additions and 73 deletions

View File

@ -5,7 +5,12 @@ pnpm-lock.yaml
/locale /locale
/templates/**/*.md /templates/**/*.md
/tools/setup/emoji/emoji_map.json /tools/setup/emoji/emoji_map.json
/web/third /web/third/*
!/web/third/marked
/web/third/marked/*
!/web/third/marked/lib
/web/third/marked/lib/*
!/web/third/marked/lib/marked.d.ts
/zerver/tests/fixtures /zerver/tests/fixtures
/zerver/webhooks/*/doc.md /zerver/webhooks/*/doc.md
/zerver/webhooks/github/githubsponsors.md /zerver/webhooks/github/githubsponsors.md

View File

@ -6,19 +6,22 @@ of the upstream library.
import {PrimitiveValue} from "url-template"; import {PrimitiveValue} from "url-template";
export class Renderer { declare class Renderer {
code: (code: string) => string; code: (code: string) => string;
link: (href: string, title: string, text: string) => string; link: (href: string, title: string, text: string) => string;
br: () => string; br: () => string;
} }
export type RegExpOrStub = RegExp | { declare namespace marked {
type RegExpOrStub =
| RegExp
| {
exec(string: string): RegExpExecArray | null; exec(string: string): RegExpExecArray | null;
}; };
export type LinkifierMatch = PrimitiveValue | PrimitiveValue[] | Record<string, PrimitiveValue>; type LinkifierMatch = PrimitiveValue | PrimitiveValue[] | Record<string, PrimitiveValue>;
export type ParseOptions = { type ParseOptions = {
get_linkifier_regexes: () => RegExp[]; get_linkifier_regexes: () => RegExp[];
linkifierHandler: (pattern: RegExp, matches: LinkifierMatch[]) => string; linkifierHandler: (pattern: RegExp, matches: LinkifierMatch[]) => string;
emojiHandler: (emoji_name: string) => string; emojiHandler: (emoji_name: string) => string;
@ -44,58 +47,59 @@ type MarkedOptions = ParseOptions & {
groupMentionHandler: (name: string, silently: boolean) => string | undefined; groupMentionHandler: (name: string, silently: boolean) => string | undefined;
silencedMentionHandler: (quote: string) => string; silencedMentionHandler: (quote: string) => string;
}; };
}
declare const marked: { declare const marked: {
// Note: We don't use the `callback` option in any of our code. // Note: We don't use the `callback` option in any of our code.
(src: string, opt: MarkedOptions, callback?: any): string; (src: string, opt: marked.MarkedOptions, callback?: any): string;
Lexer: { Lexer: {
rules: { rules: {
tables: { tables: {
newline: RegExpOrStub; newline: marked.RegExpOrStub;
code: RegExpOrStub; code: marked.RegExpOrStub;
fences: RegExpOrStub; fences: marked.RegExpOrStub;
hr: RegExpOrStub; hr: marked.RegExpOrStub;
heading: RegExpOrStub; heading: marked.RegExpOrStub;
nptable: RegExpOrStub; nptable: marked.RegExpOrStub;
blockquote: RegExpOrStub; blockquote: marked.RegExpOrStub;
list: RegExpOrStub; list: marked.RegExpOrStub;
html: RegExpOrStub; html: marked.RegExpOrStub;
def: RegExpOrStub; def: marked.RegExpOrStub;
table: RegExpOrStub; table: marked.RegExpOrStub;
paragraph: RegExpOrStub; paragraph: marked.RegExpOrStub;
text: RegExpOrStub; text: marked.RegExpOrStub;
bullet: RegExpOrStub; bullet: marked.RegExpOrStub;
item: RegExpOrStub; item: marked.RegExpOrStub;
_ta: RegExpOrStub; _ta: marked.RegExpOrStub;
}; };
}; };
}; };
InlineLexer: { InlineLexer: {
rules: { rules: {
zulip: { zulip: {
escape: RegExpOrStub; escape: marked.RegExpOrStub;
autolink: RegExpOrStub; autolink: marked.RegExpOrStub;
url: RegExpOrStub; url: marked.RegExpOrStub;
tag: RegExpOrStub; tag: marked.RegExpOrStub;
link: RegExpOrStub; link: marked.RegExpOrStub;
reflink: RegExpOrStub; reflink: marked.RegExpOrStub;
nolink: RegExpOrStub; nolink: marked.RegExpOrStub;
strong: RegExpOrStub; strong: marked.RegExpOrStub;
em: RegExpOrStub; em: marked.RegExpOrStub;
code: RegExpOrStub; code: marked.RegExpOrStub;
br: RegExpOrStub; br: marked.RegExpOrStub;
del: RegExpOrStub; del: marked.RegExpOrStub;
emoji: RegExpOrStub; emoji: marked.RegExpOrStub;
unicodeemoji: RegExpOrStub; unicodeemoji: marked.RegExpOrStub;
usermention: RegExpOrStub; usermention: marked.RegExpOrStub;
groupmention: RegExpOrStub; groupmention: marked.RegExpOrStub;
stream: RegExpOrStub; stream: marked.RegExpOrStub;
tex: RegExpOrStub; tex: marked.RegExpOrStub;
timestamp: RegExpOrStub; timestamp: marked.RegExpOrStub;
text: RegExpOrStub; text: marked.RegExpOrStub;
_inside: RegExpOrStub; _inside: marked.RegExpOrStub;
_href: RegExpOrStub; _href: marked.RegExpOrStub;
stream_topic: RegExpOrStub; stream_topic: marked.RegExpOrStub;
}; };
}; };
}; };
@ -103,4 +107,4 @@ declare const marked: {
stashHtml: (html: string, safe: boolean) => string; stashHtml: (html: string, safe: boolean) => string;
}; };
export default marked; export = marked;