Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion web/src/utils/markdown-manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ export function toggleTaskAtLine(markdown: string, lineNumber: number, checked:

return lines.join("\n");
}

export function isInsideCodeBlock(lines :string [] , index : number):boolean{
let inside = false;
for(let i = 0 ; i <= index ; i++){
if(lines[i].startsWith("```")){
inside = !inside;
}
}
return inside;
}
export function toggleTaskAtIndex(markdown: string, taskIndex: number, checked: boolean): string {
const lines = markdown.split("\n");
const taskPattern = /^(\s*[-*+]\s+)\[([ xX])\](\s+.*)$/;

let currentTaskIndex = 0;

for (let i = 0; i < lines.length; i++) {
if (isInsideCodeBlock(lines, i)) continue;
const line = lines[i];
const match = line.match(taskPattern);

Expand Down