Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-11-30 11:10:19 +08:00
commit f0c8e08972
4 changed files with 55 additions and 24 deletions

View file

@ -199,7 +199,7 @@ export class Inbox extends Model {
${linkHTML}
</div>
<div class="b3-typography b3-typography--default" style="padding: 0 8px 8px">
${(Lute.New()).MarkdownStr("", data.shorthandContent)}
${data.shorthandContent}
</div>`;
/// #else
if (data.shorthandURL) {
@ -214,7 +214,7 @@ ${(Lute.New()).MarkdownStr("", data.shorthandContent)}
${linkHTML}
</div>
<div class="b3-typography b3-typography--default" style="padding: 0 8px 8px;user-select: text">
${(Lute.New()).MarkdownStr("", data.shorthandContent)}
${data.shorthandContent}
</div>`;
/// #endif
}
@ -332,7 +332,7 @@ ${(Lute.New()).MarkdownStr("", data.shorthandContent)}
notebook: toNotebook[0],
path: pathPosix().join(getDisplayName(toPath[0], false, true), Lute.NewNodeID() + ".sy"),
title: replaceFileName(response.data.shorthandTitle),
md: response.data.shorthandContent,
md: response.data.shorthandMd,
}, (docResponse) => {
this.remove(item);
fetchPost("/api/format/netAssets2LocalAssets", {id: docResponse.data.id});

View file

@ -26,27 +26,27 @@ export const pasteEscaped = async (protyle: IProtyle, nodeElement: Element) => {
// task-blog-2~default~baiduj 无法原义粘贴含有 `~foo~` 的文本 https://github.com/siyuan-note/siyuan/issues/5523
// 这里必须多加一个反斜杆,因为 Lute 在进行 Markdown 嵌套节点转换平铺标记节点时会剔除 Backslash 节点,
// 多加入的一个反斜杆会作为文本节点保留下来,后续 Spin 时刚好用于转义标记符 https://github.com/siyuan-note/siyuan/issues/6341
clipText = clipText.replace(/\\/g, "\\\\\\\\")
.replace(/\*/g, "\\\\\\*")
.replace(/\_/g, "\\\\\\_")
.replace(/\[/g, "\\\\\\[")
.replace(/\]/g, "\\\\\\]")
.replace(/\!/g, "\\\\\\!")
.replace(/\`/g, "\\\\\\`")
.replace(/\</g, "\\\\\\<")
.replace(/\>/g, "\\\\\\>")
.replace(/\&/g, "\\\\\\&")
.replace(/\~/g, "\\\\\\~")
.replace(/\{/g, "\\\\\\{")
.replace(/\}/g, "\\\\\\}")
.replace(/\(/g, "\\\\\\(")
.replace(/\)/g, "\\\\\\)")
.replace(/\=/g, "\\\\\\=")
.replace(/\#/g, "\\\\\\#")
.replace(/\$/g, "\\\\\\$")
.replace(/\^/g, "\\\\\\^")
.replace(/\|/g, "\\\\\\|");
// 多加入的一个反斜杆会作为文本节点保留下来,后续 Spin 时刚好用于转义标记符
clipText = clipText.replace(/\\/g, "\\\\")
.replace(/\*/g, "\\*")
.replace(/_/g, "\\_")
.replace(/\[/g, "\\[")
.replace(/]/g, "\\]")
.replace(/!/g, "\\!")
.replace(/`/g, "\\`")
.replace(/</g, "\\<")
.replace(/>/g, "\\>")
.replace(/&/g, "\\&")
.replace(/~/g, "\\~")
.replace(/\{/g, "\\{")
.replace(/}/g, "\\}")
.replace(/\(/g, "\\(")
.replace(/\)/g, "\\)")
.replace(/=/g, "\\=")
.replace(/#/g, "\\#")
.replace(/\$/g, "\\$")
.replace(/\^/g, "\\^")
.replace(/\|/g, "\\|");
pasteText(protyle, clipText, nodeElement);
} catch (e) {
console.log(e);

View file

@ -262,6 +262,7 @@ interface ISnippet {
interface IInbox {
oId: string
shorthandContent: string
shorthandMd: string
shorthandDesc: string
shorthandFrom: number
shorthandTitle: string

View file

@ -23,11 +23,13 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
"github.com/88250/gulu"
"github.com/88250/lute/parse"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/conf"
@ -456,6 +458,15 @@ func GetCloudShorthand(id string) (ret map[string]interface{}, err error) {
t, _ := strconv.ParseInt(id, 10, 64)
hCreated := util.Millisecond2Time(t)
ret["hCreated"] = hCreated.Format("2006-01-02 15:04")
md := ret["shorthandContent"].(string)
ret["shorthandMd"] = md
luteEngine := NewLute()
luteEngine.SetFootnotes(true)
tree := parse.Parse("", []byte(md), luteEngine.ParseOptions)
content := luteEngine.ProtylePreview(tree, luteEngine.RenderOptions)
ret["shorthandContent"] = content
return
}
@ -483,6 +494,11 @@ func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
err = errors.New(result["msg"].(string))
return
}
luteEngine := NewLute()
audioRegexp := regexp.MustCompile("<audio.*>.*</audio>")
videoRegexp := regexp.MustCompile("<video.*>.*</video>")
fileRegexp := regexp.MustCompile("\\[文件]\\(.*\\)")
shorthands := result["data"].(map[string]interface{})["shorthands"].([]interface{})
for _, item := range shorthands {
shorthand := item.(map[string]interface{})
@ -490,6 +506,20 @@ func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
t, _ := strconv.ParseInt(id, 10, 64)
hCreated := util.Millisecond2Time(t)
shorthand["hCreated"] = hCreated.Format("2006-01-02 15:04")
desc := shorthand["shorthandDesc"].(string)
desc = audioRegexp.ReplaceAllString(desc, " 语音 ")
desc = videoRegexp.ReplaceAllString(desc, " 视频 ")
desc = fileRegexp.ReplaceAllString(desc, " 文件 ")
desc = strings.ReplaceAll(desc, "\n\n", "")
desc = strings.TrimSpace(desc)
shorthand["shorthandDesc"] = desc
md := shorthand["shorthandContent"].(string)
shorthand["shorthandMd"] = md
tree := parse.Parse("", []byte(md), luteEngine.ParseOptions)
content := luteEngine.ProtylePreview(tree, luteEngine.RenderOptions)
shorthand["shorthandContent"] = content
}
return
}