mirror of
https://github.com/eluisjonathann/obsidian-remove-task-format.git
synced 2026-07-22 07:45:27 +00:00
25 lines
1.1 KiB
JavaScript
25 lines
1.1 KiB
JavaScript
const { Plugin } = require('obsidian');
|
|
|
|
module.exports = class RemoveTaskPlugin extends Plugin {
|
|
async onload() {
|
|
this.addCommand({
|
|
id: 'remove-task-format',
|
|
name: 'Remove task format from current line',
|
|
editorCallback: (editor, view) => {
|
|
const cursor = editor.getCursor();
|
|
const lineText = editor.getLine(cursor.line);
|
|
|
|
// Matches indentation, optional list marker (e.g. - or * or 1.) and checkbox
|
|
const taskRegex = /^(\s*)([-*+]|\d+\.)?\s*\[[xX ]\]\s*(.*)$/;
|
|
|
|
if (taskRegex.test(lineText)) {
|
|
// Removes both the list marker (hyphen/number) and the checkbox, keeping indentation and text
|
|
const newLineText = lineText.replace(taskRegex, (match, indentation, prefix, content) => {
|
|
return `${indentation}${content}`;
|
|
});
|
|
editor.setLine(cursor.line, newLineText);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|