opt: refactor chat session page for mobile device

This commit is contained in:
RockYang
2024-01-25 14:07:10 +08:00
parent cd760bbd84
commit 4a00809061
10 changed files with 324 additions and 104 deletions

View File

@@ -166,3 +166,34 @@ export function isImage(url) {
return expr.test(url);
}
export function processContent(content) {
//process img url
const linkRegex = /(https?:\/\/\S+)/g;
const links = content.match(linkRegex);
if (links) {
for (let link of links) {
if (isImage(link)) {
const index = content.indexOf(link)
if (content.substring(index - 1, 2) !== "]") {
content = content.replace(link, "\n![](" + link + ")\n")
}
}
}
}
// 处理引用块
if (content.indexOf("\n") === -1) {
return content
}
const texts = content.split("\n")
const lines = []
for (let txt of texts) {
lines.push(txt)
if (txt.startsWith(">")) {
lines.push("\n")
}
}
return lines.join("\n")
}