From 13c44efad97d2080bff58171b256a1ad59059adb Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 8 Jun 2024 00:17:35 -0700 Subject: [PATCH] marked: Fix type stub to declare marked as a CommonJS module. Signed-off-by: Anders Kaseorg --- .prettierignore | 7 +- web/third/marked/lib/marked.d.ts | 148 ++++++++++++++++--------------- 2 files changed, 82 insertions(+), 73 deletions(-) diff --git a/.prettierignore b/.prettierignore index a9fdd4d0c4..bb611591d0 100644 --- a/.prettierignore +++ b/.prettierignore @@ -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 diff --git a/web/third/marked/lib/marked.d.ts b/web/third/marked/lib/marked.d.ts index 6eb6f5cb6f..e229afb892 100644 --- a/web/third/marked/lib/marked.d.ts +++ b/web/third/marked/lib/marked.d.ts @@ -4,98 +4,102 @@ we only use parts of the marked API and are using a fork of the upstream library. */ -import { PrimitiveValue } from "url-template"; +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 | { - exec(string: string): RegExpExecArray | null; -}; +declare namespace marked { + type RegExpOrStub = + | RegExp + | { + exec(string: string): RegExpExecArray | null; + }; -export type LinkifierMatch = PrimitiveValue | PrimitiveValue[] | Record; + type LinkifierMatch = PrimitiveValue | PrimitiveValue[] | Record; -export type ParseOptions = { - get_linkifier_regexes: () => RegExp[]; - linkifierHandler: (pattern: RegExp, matches: LinkifierMatch[]) => string; - emojiHandler: (emoji_name: string) => string; - unicodeEmojiHandler: (unicode_emoji: string) => string; - streamHandler: (stream_name: string) => string | undefined; - streamTopicHandler: (stream_name: string, topic: string) => string | undefined; - texHandler: (tex: string, fullmatch: string) => string; - timestampHandler: (time_string: string) => string; - gfm: boolean; - tables: boolean; - breaks: boolean; - pedantic: boolean; - sanitize: boolean; - smartLists: boolean; - smartypants: boolean; - zulip: boolean; - renderer: Renderer; - preprocessors: ((src: string) => string)[]; -}; + type ParseOptions = { + get_linkifier_regexes: () => RegExp[]; + linkifierHandler: (pattern: RegExp, matches: LinkifierMatch[]) => string; + emojiHandler: (emoji_name: string) => string; + unicodeEmojiHandler: (unicode_emoji: string) => string; + streamHandler: (stream_name: string) => string | undefined; + streamTopicHandler: (stream_name: string, topic: string) => string | undefined; + texHandler: (tex: string, fullmatch: string) => string; + timestampHandler: (time_string: string) => string; + gfm: boolean; + tables: boolean; + breaks: boolean; + pedantic: boolean; + sanitize: boolean; + smartLists: boolean; + smartypants: boolean; + zulip: boolean; + renderer: Renderer; + preprocessors: ((src: string) => string)[]; + }; -type MarkedOptions = ParseOptions & { - userMentionHandler: (mention: string, silently: boolean) => string | undefined; - groupMentionHandler: (name: string, silently: boolean) => string | undefined; - silencedMentionHandler: (quote: string) => string; -}; + type MarkedOptions = ParseOptions & { + userMentionHandler: (mention: string, silently: boolean) => string | undefined; + 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;