Skip to content

Commit

Permalink
Merge remote-tracking branch 'forke-siyuan/dev' into v0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed May 1, 2024
2 parents 5743b25 + 6e79995 commit a3a44e8
Show file tree
Hide file tree
Showing 26 changed files with 1,598 additions and 49 deletions.
1,501 changes: 1,501 additions & 0 deletions app/appearance/langs/ja_JP.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/electron-builder-darwin-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extraResources:
filter: "!**/{.DS_Store}"
- from: "appearance/langs"
to: "appearance/langs"
filter: "!**/{.DS_Store}"
filter: "!**/{.DS_Store,zh_CHT.json,fr_FR.json,es_ES.json}"
- from: "appearance/emojis"
to: "appearance/emojis"
filter: "!**/{.DS_Store}"
Expand Down
2 changes: 1 addition & 1 deletion app/electron-builder-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extraResources:
filter: "!**/{.DS_Store}"
- from: "appearance/langs"
to: "appearance/langs"
filter: "!**/{.DS_Store}"
filter: "!**/{.DS_Store,zh_CHT.json,fr_FR.json,es_ES.json}"
- from: "appearance/emojis"
to: "appearance/emojis"
filter: "!**/{.DS_Store}"
Expand Down
2 changes: 1 addition & 1 deletion app/electron-builder-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extraResources:
filter: "!**/{.DS_Store}"
- from: "appearance/langs"
to: "appearance/langs"
filter: "!**/{.DS_Store}"
filter: "!**/{.DS_Store,zh_CHT.json,fr_FR.json,es_ES.json}"
- from: "appearance/emojis"
to: "appearance/emojis"
filter: "!**/{.DS_Store}"
Expand Down
2 changes: 1 addition & 1 deletion app/electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extraResources:
filter: "!**/{.DS_Store}"
- from: "appearance/langs"
to: "appearance/langs"
filter: "!**/{.DS_Store}"
filter: "!**/{.DS_Store,zh_CHT.json,fr_FR.json,es_ES.json}"
- from: "appearance/emojis"
to: "appearance/emojis"
filter: "!**/{.DS_Store}"
Expand Down
2 changes: 2 additions & 0 deletions app/electron/init.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ <h2 class="BBN">Sillot - 汐洛</h2>
<select class="b3-select lang">
<option value="en_US">English</option>
<option value="zh_CN">中文</option>
<option value="ja_JP">日本語</option>
</select>
</label>
<label class="b3-label">
Expand Down Expand Up @@ -257,6 +258,7 @@ <h2 class="BBN">汐洛 - Sillot</h2>
<select class="b3-select lang">
<option value="en_US">English</option>
<option value="zh_CN">中文</option>
<option value="ja_JP">日本語</option>
</select>
</label>
<label class="b3-label">
Expand Down
2 changes: 1 addition & 1 deletion app/src/block/Panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class BlockPanel {
action.push(Constants.CB_GET_ALL);
} else {
action.push(Constants.CB_GET_CONTEXT);
action.push(Constants.CB_GET_HL);
// 不需要高亮 https://github.com/siyuan-note/siyuan/issues/11160#issuecomment-2084652764
}

if (this.isBacklink) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/block/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ export const jumpToParent = (protyle: IProtyle, nodeElement: Element, type: "par
if (!targetId) {
return;
}

openFileById({
app: protyle.app,
id: targetId,
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""]
})
});
};
Expand Down
2 changes: 1 addition & 1 deletion app/src/boot/onGetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export const initWindow = async (app: App) => {
const response = await fetchSyncPost("/api/template/renderSprig", {template: window.siyuan.config.export.pdfFooter});
ipcData.pdfOptions.displayHeaderFooter = true;
ipcData.pdfOptions.headerTemplate = "<span></span>";
ipcData.pdfOptions.footerTemplate = `<div style="text-align:center;width:100%;font-size:8px;line-height:12px;">
ipcData.pdfOptions.footerTemplate = `<div style="text-align:center;width:100%;font-size:10px;line-height:12px;">
${response.data.replace("%pages", "<span class=totalPages></span>").replace("%page", "<span class=pageNumber></span>")}
</div>`;
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/config/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Constants} from "../constants";
import {exportLayout, resetLayout} from "../layout/util";
import {isBrowser} from "../util/functions";
import {fetchPost} from "../util/fetch";
import {genOptions} from "../util/genOptions";
import {genLangOptions, genOptions} from "../util/genOptions";
import {openSnippets} from "./util/snippets";
import {loadAssets} from "../util/assets";
import {resetFloatDockSize} from "../layout/dock/util";
Expand Down Expand Up @@ -95,7 +95,7 @@ export const appearance = {
<div class="b3-label__text">${window.siyuan.languages.language1}</div>
</div>
<span class="fn__space"></span>
<select id="lang" class="b3-select fn__flex-center fn__size200">${genOptions(window.siyuan.config.langs, window.siyuan.config.appearance.lang)}</select>
<select id="lang" class="b3-select fn__flex-center fn__size200">${genLangOptions(window.siyuan.config.langs, window.siyuan.config.appearance.lang)}</select>
</div>
<div class="b3-label config__item${isBrowser() ? " fn__none" : " fn__flex"}">
<div class="fn__flex-1">
Expand Down
1 change: 1 addition & 0 deletions app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export abstract class Constants extends SConst { // Sillot extend
en_US: "20210808180117-6v0mkxr",
fr_FR: "20210808180117-6v0mkxr",
es_ES: "20210808180117-6v0mkxr",
ja_JP: "20210808180117-6v0mkxr",
};
public static readonly QUICK_DECK_ID = "20230218211946-2kw8jgx";

Expand Down
4 changes: 2 additions & 2 deletions app/src/mobile/settings/appearance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {fetchPost} from "../../util/fetch";
import {genOptions} from "../../util/genOptions";
import {genLangOptions, genOptions} from "../../util/genOptions";
import {openModel} from "../menu/model";

export const initAppearance = () => {
Expand Down Expand Up @@ -41,7 +41,7 @@ export const initAppearance = () => {
<div class="b3-label">
${window.siyuan.languages.language}
<div class="fn__hr"></div>
<select id="lang" class="b3-select fn__block">${genOptions(window.siyuan.config.langs, window.siyuan.config.appearance.lang)}</select>
<select id="lang" class="b3-select fn__block">${genLangOptions(window.siyuan.config.langs, window.siyuan.config.appearance.lang)}</select>
<div class="b3-label__text">${window.siyuan.languages.language1}</div>
</div>`,
bindEvent(modelMainElement: HTMLElement) {
Expand Down
5 changes: 4 additions & 1 deletion app/src/plugin/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export class Setting {
if (!item.actionElement && item.createActionElement) {
actionElement = item.createActionElement();
}
const tagName = actionElement?.classList.contains("b3-switch")?"label":"div";
const tagName = actionElement?.classList.contains("b3-switch") ? "label" : "div";
if (typeof item.direction === "undefined") {
item.direction = "TEXTAREA" === actionElement.tagName ? "row" : "column";
}
if (item.direction === "row") {
html = `<${tagName} class="b3-label">
<div class="fn__block">
Expand Down
8 changes: 0 additions & 8 deletions app/src/protyle/render/highlightRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
languageElement.style.marginLeft = "";
}
}
// 搜索定位
const layoutElement = hasClosestByClassName(block, "search__layout", true);
if (layoutElement && block.parentElement.getAttribute("data-node-id") === layoutElement.querySelector("#searchList > .b3-list-item--focus")?.getAttribute("data-node-id")) {
const matchElement = block.querySelector('span[data-type="search-mark"]');
if (matchElement) {
matchElement.scrollIntoView();
}
}
block.innerHTML = window.hljs.highlight(
block.textContent + (block.textContent.endsWith("\n") ? "" : "\n"), // https://github.com/siyuan-note/siyuan/issues/4609
{
Expand Down
16 changes: 15 additions & 1 deletion app/src/protyle/wysiwyg/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
getLastBlock,
getNextBlock,
getPreviousBlock,
getTopAloneElement,
getTopAloneElement, hasNextSibling,
hasPreviousSibling,
isNotEditBlock,
} from "./getBlock";
Expand Down Expand Up @@ -809,6 +809,20 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.stopPropagation();
event.preventDefault();
return;
} else {
// 图片前 Delete 无效 https://github.com/siyuan-note/siyuan/issues/11209
let nextSibling = hasNextSibling(range.startContainer) as Element;
if (nextSibling) {
if (nextSibling.nodeType === 3 && nextSibling.textContent === Constants.ZWSP) {
nextSibling = nextSibling.nextSibling as Element;
}
if (nextSibling.nodeType === 1 && nextSibling.classList.contains("img")) {
removeImage(nextSibling as Element, nodeElement, range, protyle);
event.stopPropagation();
event.preventDefault();
return;
}
}
}
} else {
const currentNode = range.startContainer.childNodes[range.startOffset - 1] as HTMLElement;
Expand Down
17 changes: 9 additions & 8 deletions app/src/protyle/wysiwyg/remove.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import {
focusBlock,
focusByRange,
focusByWbr,
getSelectionOffset,
setLastNodeRange
} from "../util/selection";
import {focusBlock, focusByRange, focusByWbr, getSelectionOffset, setLastNodeRange} from "../util/selection";
import {
getContenteditableElement,
getLastBlock,
getNextBlock,
getPreviousBlock,
getTopAloneElement,
getTopEmptyElement, hasNextSibling, hasPreviousSibling
getTopEmptyElement,
hasNextSibling,
hasPreviousSibling
} from "./getBlock";
import {transaction, turnsIntoTransaction, updateTransaction} from "./transaction";
import {cancelSB, genEmptyElement} from "../../block/util";
Expand Down Expand Up @@ -420,6 +416,11 @@ export const removeImage = (imgSelectElement: Element, nodeElement: HTMLElement,
imgSelectElement.remove();
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
focusByWbr(nodeElement, range);
// 不太清楚为什么删除图片后无法上下键定位,但重绘后就好了 https://ld246.com/article/1714314625702
const editElement = getContenteditableElement(nodeElement);
if (editElement.innerHTML.trim() === "") {
editElement.innerHTML = "";
}
};

const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDelete = false) => {
Expand Down
6 changes: 5 additions & 1 deletion app/src/search/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,11 @@ export const getArticle = (options: {
if (matchElement) {
matchElement.classList.add("search-mark--hl");
const contentRect = options.edit.protyle.contentElement.getBoundingClientRect();
options.edit.protyle.contentElement.scrollTop = options.edit.protyle.contentElement.scrollTop + matchElement.getBoundingClientRect().top - contentRect.top - contentRect.height / 2;
const matchRectTop = matchElement.getBoundingClientRect().top; // 需前置,否则代码高亮后会移除该元素
setTimeout(() => {
// 等待 scrollCenter 定位后再滚动
options.edit.protyle.contentElement.scrollTop = options.edit.protyle.contentElement.scrollTop + matchRectTop - contentRect.top - contentRect.height / 2;
});
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion app/src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ declare namespace Config {
* User interface language
* Same as {@link IAppearance.lang}
*/
export type TLang = "en_US" | "es_ES" | "fr_FR" | "zh_CHT" | "zh_CN";
export type TLang = "en_US" | "zh_CN" | "ja_JP";

/**
* SiYuan bazaar related configuration
Expand Down
9 changes: 9 additions & 0 deletions app/src/util/genOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ export const genOptions = (data: string[] | { label: string, name: string }[], k
});
return html;
};

export const genLangOptions = (data: { label: string, name: string }[], key: string) => {
let html = "";
data.forEach((item: { label: string, name: string }) => {
html += `<option value="${item.name}" ${key === item.name ? "selected" : ""}>${item.label} (${item.name})</option>`;
});
return html;
};

2 changes: 1 addition & 1 deletion app/stage/protyle/js/lute/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kernel/api/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func extensionCopy(c *gin.Context) {
}

luteEngine := util.NewStdLute()
md := luteEngine.HTML2Md(dom)
md, _ := model.HTML2Markdown(dom)
md = strings.TrimSpace(md)

var unlinks []*ast.Node
Expand Down
4 changes: 2 additions & 2 deletions kernel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require (
github.com/88250/clipboard v0.1.5
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
github.com/88250/gulu v1.2.3-0.20240324024901-3c1bb82cba30
github.com/88250/lute v1.7.7-0.20240426152525-692d31b09cd2
github.com/88250/gulu v1.2.3-0.20240501100058-dfdea8ef020e
github.com/88250/lute v1.7.7-0.20240501085643-eb6f97b5b990
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
Expand Down
8 changes: 4 additions & 4 deletions kernel/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7 h1:MafIFwSS0x6A4
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7/go.mod h1:HrKCCTin3YNDSLBD02K0AOljjV6eNwc3/zyEI+xyV1I=
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceTVVqrYaDlLio2QSKbXMUmAZPbzCwT5eNCw=
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20240324024901-3c1bb82cba30 h1:IeE4DVRWnVpcbMj7gGZoSMiBWs3h/ihiyOmualS1Mas=
github.com/88250/gulu v1.2.3-0.20240324024901-3c1bb82cba30/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20240426152525-692d31b09cd2 h1:ij6zgH3jCeBzRQ1hRgJzuEFwyHBO8coK5Jn1fCFAamo=
github.com/88250/lute v1.7.7-0.20240426152525-692d31b09cd2/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/gulu v1.2.3-0.20240501100058-dfdea8ef020e h1:sJ4Cab5UYEG1LxV9auNtfCc4ePy/TYg+m1gQx7NMDU0=
github.com/88250/gulu v1.2.3-0.20240501100058-dfdea8ef020e/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20240501085643-eb6f97b5b990 h1:aDwkV9eHMm0v14+yCKSjBupfuh9lMZmWGWmMinJpfGc=
github.com/88250/lute v1.7.7-0.20240501085643-eb6f97b5b990/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
Expand Down
33 changes: 25 additions & 8 deletions kernel/model/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,20 @@ func GetBlockSiblingID(id string) (parent, previous, next string) {

if nil != parentList {
parent = parentList.ID
if flb := treenode.FirstLeafBlock(parentList); nil != flb {
if flb := firstChild(parentList); nil != flb {
parent = flb.ID
}

if parentListItem.Previous != nil {
previous = parentListItem.Previous.ID
if flb := treenode.FirstLeafBlock(parentListItem.Previous); nil != flb {
if flb := firstChild(parentListItem.Previous); nil != flb {
previous = flb.ID
}
}

if parentListItem.Next != nil {
next = parentListItem.Next.ID
if flb := treenode.FirstLeafBlock(parentListItem.Next); nil != flb {
if flb := firstChild(parentListItem.Next); nil != flb {
next = flb.ID
}
}
Expand All @@ -170,35 +170,37 @@ func GetBlockSiblingID(id string) (parent, previous, next string) {

if nil != current.Parent && current.Parent.IsBlock() {
parent = current.Parent.ID
if flb := treenode.FirstLeafBlock(current.Parent); nil != flb {
if flb := firstChild(current.Parent); nil != flb {
parent = flb.ID
}

if ast.NodeDocument == current.Parent.Type {
parent = current.Parent.ID

if nil != current.Previous && current.Previous.IsBlock() {
previous = current.Previous.ID
if flb := treenode.FirstLeafBlock(current.Previous); nil != flb {
if flb := firstChild(current.Previous); nil != flb {
previous = flb.ID
}
}

if nil != current.Next && current.Next.IsBlock() {
next = current.Next.ID
if flb := treenode.FirstLeafBlock(current.Next); nil != flb {
if flb := firstChild(current.Next); nil != flb {
next = flb.ID
}
}
} else {
if nil != current.Parent.Previous && current.Parent.Previous.IsBlock() {
previous = current.Parent.Previous.ID
if flb := treenode.FirstLeafBlock(current.Parent.Previous); nil != flb {
if flb := firstChild(current.Parent.Previous); nil != flb {
previous = flb.ID
}
}

if nil != current.Parent.Next && current.Parent.Next.IsBlock() {
next = current.Parent.Next.ID
if flb := treenode.FirstLeafBlock(current.Parent.Next); nil != flb {
if flb := firstChild(current.Parent.Next); nil != flb {
next = flb.ID
}
}
Expand All @@ -208,6 +210,21 @@ func GetBlockSiblingID(id string) (parent, previous, next string) {
return
}

func firstChild(node *ast.Node) (ret *ast.Node) {
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}

if n.IsBlock() {
ret = n
return ast.WalkStop
}
return ast.WalkContinue
})
return
}

func IsBlockFolded(id string) bool {
for i := 0; i < 32; i++ {
b, _ := getBlock(id, nil)
Expand Down
6 changes: 5 additions & 1 deletion kernel/model/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"runtime/debug"
"sort"
"strconv"
Expand Down Expand Up @@ -928,8 +929,11 @@ func processBase64Img(n *ast.Node, dest string, assetDirPath string, err error)
os.MkdirAll(base64TmpDir, 0755)

sep := strings.Index(dest, ";base64,")
str := strings.TrimSpace(dest[sep+8:])
re := regexp.MustCompile(`(?i)%0A`)
str = re.ReplaceAllString(str, "\n")
var decodeErr error
unbased, decodeErr := base64.StdEncoding.DecodeString(dest[sep+8:])
unbased, decodeErr := base64.StdEncoding.DecodeString(str)
if nil != decodeErr {
logging.LogErrorf("decode base64 image failed: %s", decodeErr)
return
Expand Down
Loading

1 comment on commit a3a44e8

@Soltus
Copy link
Member Author

@Soltus Soltus commented on a3a44e8 May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

langs 过滤无效 #671

Please sign in to comment.