-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from led-mirage/feature/support-for-claude
Feature/support for claude
- Loading branch information
Showing
7 changed files
with
202 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,11 @@ | |
displayAlign: "left" | ||
} | ||
}; | ||
marked.setOptions( | ||
{ | ||
breaks: true | ||
} | ||
); | ||
</script> | ||
<script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-mml-chtml.js"></script> | ||
</head> | ||
|
@@ -326,7 +331,8 @@ | |
const messageElement = document.createElement("div"); | ||
messageElement.classList.add("message-text"); | ||
if (role === "assistant") { | ||
let html = escapeTex(messageText); | ||
let html = convertTextToHtmlWithMarkdown(messageText); | ||
html = escapeTex(html); | ||
html = adjustURL(html); | ||
html = marked.parse(html); | ||
html = unescapeTex(html); | ||
|
@@ -348,6 +354,26 @@ | |
chatMessagesContainer.appendChild(chatMessageElement); | ||
} | ||
|
||
// マークダウンテキスト内のコードブロックを保護しながらHTML変換する関数 | ||
function convertTextToHtmlWithMarkdown(text) { | ||
// コードブロックを一時保存 | ||
let codeBlocks = []; | ||
text = text.replace(/```[\s\S]*?```/g, match => { | ||
codeBlocks.push(match); | ||
return `__CODE_BLOCK_${codeBlocks.length-1}__`; | ||
}); | ||
|
||
// バッククォート文字を変換 | ||
text = text.replace(/\\`/g, '\\\''); | ||
|
||
// コードブロックを戻す | ||
codeBlocks.forEach((block, i) => { | ||
text = text.replace(`__CODE_BLOCK_${i}__`, block); | ||
}); | ||
|
||
return text; | ||
} | ||
|
||
// markedがリンクに連続する文字列全体をリンクに変換してしまう問題に対処 | ||
function adjustURL(text) { | ||
// https://またはhttp://では始まらない、www.で始まるドメイン名の前後にバッククォートを入れる | ||
|
@@ -571,7 +597,8 @@ | |
const messageTextElements = document.querySelectorAll("#chat-messages .message-text"); | ||
const lastMessageTextElement = messageTextElements[messageTextElements.length - 1]; | ||
if(lastMessageTextElement) { | ||
let html = escapeTex(content); | ||
let html = convertTextToHtmlWithMarkdown(content); | ||
html = escapeTex(html); | ||
html = adjustURL(html); | ||
html = marked.parse(html); | ||
html = unescapeTex(html); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.