From e9c5cc5ebeaf3432f35d8adbd0e669e443f191c0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 25 Jul 2023 20:40:48 +0900 Subject: [PATCH] Support image resizing in markdown --- src/controller/title-generator.ts | 2 +- src/extensions/bingchat/bingchat-api.ts | 2 +- src/model/chat-api.ts | 2 +- src/util/streamed-markdown.ts | 13 +++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/controller/title-generator.ts b/src/controller/title-generator.ts index 4edb510..14c4110 100644 --- a/src/controller/title-generator.ts +++ b/src/controller/title-generator.ts @@ -34,7 +34,7 @@ The conversation is named: onMessageDelta(delta) { title += delta.content ?? ''; } }); } else if (api instanceof ChatConversationAPI && - !(api.constructor as ChatConversationAPIType).isHighlyRateLimited) { + !(api.constructor as ChatConversationAPIType).badSummarizer) { // Spawn a new conversation to ask for title generation, const newapi = api.clone() as ChatConversationAPI; await newapi.sendMessage(promptText, { diff --git a/src/extensions/bingchat/bingchat-api.ts b/src/extensions/bingchat/bingchat-api.ts index 83a6131..d6a04f7 100644 --- a/src/extensions/bingchat/bingchat-api.ts +++ b/src/extensions/bingchat/bingchat-api.ts @@ -29,7 +29,7 @@ type SessionData = { }; export default class BingChatAPI extends ChatConversationAPI { - static isHighlyRateLimited = true; + static badSummarizer = true; #lastContentLength: number; #lastLinks: {name: string, url: string}[]; diff --git a/src/model/chat-api.ts b/src/model/chat-api.ts index eef4519..5af92be 100644 --- a/src/model/chat-api.ts +++ b/src/model/chat-api.ts @@ -96,7 +96,7 @@ export abstract class ChatConversationAPI extends WebAPI { type ChatConversationAPIConstructorType = new (credential: APICredential) => ChatConversationAPI; export interface ChatConversationAPIType extends ChatConversationAPIConstructorType { - isHighlyRateLimited?: boolean; + badSummarizer?: boolean; canRemoveFromServer?: boolean; canRemoveMessagesAfter?: boolean; } diff --git a/src/util/streamed-markdown.ts b/src/util/streamed-markdown.ts index b4ce1b3..322f20a 100644 --- a/src/util/streamed-markdown.ts +++ b/src/util/streamed-markdown.ts @@ -69,6 +69,8 @@ export default class StreamedMarkdown { this.renderer.heading = (text: string, level: number) => { return `

${'#'.repeat(level)} ${text}

`; }; + // Support image resizing. + this.renderer.image = imageExtension; // Escape all html tags. this.renderer.html = escape; } @@ -176,3 +178,14 @@ function findStartOfDifference(a: string, b: string) { return i - 1; return i; } + +// Make Marked support specifying image size in pixels in this format: +// +// ![alt](src "=800x600") +function imageExtension(src, title, alt) { + const exec = /=\s*(\d*)\s*x\s*(\d*)\s*$/.exec(title); + let res = '' + escape(alt);
+  if (exec && exec[1]) res += ''; +}