mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-05 12:20:16 +01:00
Kernel API OCR returns text coordinate information (#11738)
* 优化setImageOCRText接口调用 * 扩展 ocr 接口,添加 ocrJSON 返回字段 * 过滤不可见字符 * 返回的ocr文本添加空格
This commit is contained in:
parent
974f1c1183
commit
c0bd645048
5 changed files with 65 additions and 34 deletions
|
|
@ -1019,7 +1019,9 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||
fetchPost("/api/asset/getImageOCRText", {
|
||||
path: imgElement.getAttribute("src")
|
||||
}, (response) => {
|
||||
element.querySelector("textarea").value = response.data.text;
|
||||
const textarea =element.querySelector("textarea")
|
||||
textarea.value = response.data.text;
|
||||
textarea.dataset.ocrText = response.data.text;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
|
|
@ -1031,11 +1033,6 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||
fetchPost("/api/asset/ocr", {
|
||||
path: imgElement.getAttribute("src"),
|
||||
force: true
|
||||
}, (response) => {
|
||||
fetchPost("/api/asset/setImageOCRText", {
|
||||
path: imgElement.getAttribute("src"),
|
||||
text: response.data.text
|
||||
});
|
||||
});
|
||||
}
|
||||
}],
|
||||
|
|
@ -1119,6 +1116,13 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||
const textElements = window.siyuan.menus.menu.element.querySelectorAll("textarea");
|
||||
textElements[0].focus();
|
||||
window.siyuan.menus.menu.removeCB = () => {
|
||||
const ocrElement = window.siyuan.menus.menu.element.querySelector('[data-type="ocr"]') as HTMLTextAreaElement;
|
||||
if (ocrElement && ocrElement.dataset.ocrText !== ocrElement.value) {
|
||||
fetchPost("/api/asset/setImageOCRText", {
|
||||
path: imgElement.getAttribute("src"),
|
||||
text: ocrElement.value
|
||||
});
|
||||
}
|
||||
imgElement.setAttribute("alt", textElements[2].value.replace(/\n|\r\n|\r|\u2028|\u2029/g, ""));
|
||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue