Skip to content

Commit

Permalink
Support image resizing in markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jul 25, 2023
1 parent e2862c5 commit e9c5cc5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/controller/title-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/bingchat/bingchat-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type SessionData = {
};

export default class BingChatAPI extends ChatConversationAPI<SessionData> {
static isHighlyRateLimited = true;
static badSummarizer = true;

#lastContentLength: number;
#lastLinks: {name: string, url: string}[];
Expand Down
2 changes: 1 addition & 1 deletion src/model/chat-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export abstract class ChatConversationAPI<T = object> extends WebAPI {
type ChatConversationAPIConstructorType<T> = new (credential: APICredential) => ChatConversationAPI<T>;

export interface ChatConversationAPIType<T = object> extends ChatConversationAPIConstructorType<T> {
isHighlyRateLimited?: boolean;
badSummarizer?: boolean;
canRemoveFromServer?: boolean;
canRemoveMessagesAfter?: boolean;
}
13 changes: 13 additions & 0 deletions src/util/streamed-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export default class StreamedMarkdown {
this.renderer.heading = (text: string, level: number) => {
return `<h4>${'#'.repeat(level)} ${text}</h4>`;
};
// Support image resizing.
this.renderer.image = imageExtension;
// Escape all html tags.
this.renderer.html = escape;
}
Expand Down Expand Up @@ -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 = '<img src="' + escape(src) + '" alt="' + escape(alt);
if (exec && exec[1]) res += '" height="' + exec[1];
if (exec && exec[2]) res += '" width="' + exec[2];
return res + '">';
}

0 comments on commit e9c5cc5

Please sign in to comment.