mirror of
https://github.com/sisyphe42/obsidian-logseqer-plugin.git
synced 2026-07-22 15:30:32 +00:00
21 lines
964 B
TypeScript
21 lines
964 B
TypeScript
// Check Logseq syntax in the document
|
|
export function checkLogseqSyntaxDOM(): number {
|
|
const noteContentElement = activeDocument.querySelector(
|
|
"body > div.app-container > div.horizontal-main-container > div > div.workspace-split.mod-vertical.mod-root > div > div.workspace-tab-container > div > div > div.view-content > div.markdown-source-view.cm-s-obsidian.mod-cm6.node-insert-event.is-folding.show-properties.is-live-preview > div > div.cm-scroller > div.cm-sizer > div.cm-contentContainer > div.cm-content.cm-lineWrapping"
|
|
);
|
|
|
|
if (!noteContentElement || !noteContentElement.instanceOf(HTMLElement)) return 0;
|
|
|
|
const text = noteContentElement.innerText || '';
|
|
const paragraphs = text.split("\n").filter((line: string) => line.trim() !== "");
|
|
const ruleRegExp = /^(\t)*- /;
|
|
let invalidCount = 0;
|
|
|
|
paragraphs.forEach((paragraph: string) => {
|
|
if (!ruleRegExp.test(paragraph)) {
|
|
invalidCount++;
|
|
}
|
|
});
|
|
|
|
return invalidCount;
|
|
}
|