Internal file paths are now Markdown image paths
In the last commit, file paths were implemented to be the full path for the API, however that is not necessary. Before this change: /data/assets/filename.svg After: assets/filename.svg The new method is what SiYuan uses for Markdown images, like 
This commit is contained in:
parent
a2503d5def
commit
5e51589ffa
8 changed files with 66 additions and 14 deletions
46
src/protyle.ts
Normal file
46
src/protyle.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import {getBlockByID, sql, updateBlock} from "@/api";
|
||||
import {escapeRegExp} from "@/helper";
|
||||
|
||||
export async function findImageBlocks(src: string) {
|
||||
|
||||
const sqlQuery = `
|
||||
SELECT id, markdown
|
||||
FROM blocks
|
||||
WHERE markdown like '%${src}%'
|
||||
`;
|
||||
|
||||
try {
|
||||
return await sql(sqlQuery);
|
||||
} catch (error) {
|
||||
console.error('Error searching for image blocks:', error);
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
export async function replaceBlockContent(
|
||||
blockId: string,
|
||||
searchStr: string,
|
||||
replaceStr: string
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
|
||||
const block = await getBlockByID(blockId);
|
||||
if (!block) {
|
||||
throw new Error('Block not found');
|
||||
}
|
||||
|
||||
const originalContent = block.markdown;
|
||||
const newContent = originalContent.replace(escapeRegExp(searchStr), replaceStr);
|
||||
|
||||
if (newContent === originalContent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await updateBlock('markdown', newContent, blockId);
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to replace block content:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue