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
/templates/**/*.md
/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/webhooks/*/doc.md
/zerver/webhooks/github/githubsponsors.md

View File

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