Skip to content

Commit

Permalink
feat: get and send all the children blocks with getBlockContent
Browse files Browse the repository at this point in the history
Update getBlockContent to recursively retrieve all the children blocks.
  • Loading branch information
Jele0794 committed Jul 14, 2024
1 parent dcdda40 commit fa188cd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { BlockEntity } from '@logseq/libs/dist/LSPlugin.user';

export async function getBlockContent(block: BlockEntity) {
let content = block.content ?? '';
export async function getBlockContent(block: BlockEntity, parentBlock = true, level = 1, content = '') {
if (parentBlock) {
content = block.content ?? '';
}
const childrens = [block.children];

let level = 1;
while (childrens.length > 0) {
const children = childrens.shift();
for (const child of children!) {
content += '\n' + '\t'.repeat(level) + '- ' + (child as BlockEntity).content;
content += await getBlockContent((child as BlockEntity), false, level + 1)
}
level += 1;
}

return content;
Expand Down

0 comments on commit fa188cd

Please sign in to comment.