Skip to content

Build your personal knowledge base with Trilium Notes

custom task states: rename task state attribute

Adorian Doran9a670c5f4161
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 3ecfde6710..ce1ea832a9 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -2753,7 +2753,7 @@ iframe.print-iframe {
/* Default checked state */
.ck-content li input[type="checkbox"]:checked,
-.tn-task-checkbox[data-task-state="done"] {
+.tn-task-checkbox[data-trilium-task-state="done"] {
--task-state-color: var(--task-checkbox-done-color);
--task-state-glyph: "";
--task-state-glyph-font-family: boxicons;
diff --git a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts
index ec82eba0a5..575a0e599b 100644
--- a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts
+++ b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts
@@ -7,7 +7,7 @@ const TODO_LIST_CHECKED_ATTRIBUTE = "todoListChecked";
/**
* The ordered task states. Includes the built-in `none`/`done` anchors — those
- * are never written as `data-task-state`; they map to the native checkbox.
+ * are never written as `data-trilium-task-state`; they map to the native checkbox.
*/
export function getConfiguredTaskStates(editor: Editor): TaskStateDef[] {
const states = editor.config.get("taskStates") as TaskStateDef[] | undefined;
@@ -47,21 +47,21 @@ export default class TodoListMultistateEditing extends Plugin {
scope: "item",
attributeName: TASK_STATE_ATTRIBUTE,
setAttributeOnDowncast(writer, value, element) {
- // Only customizable states carry `data-task-state`; none/done are native.
+ // Only customizable states carry `data-trilium-task-state`; none/done are native.
if (typeof value === "string" && stateByName.has(value) && !isAnchorState(value)) {
- writer.setAttribute("data-task-state", value, element);
+ writer.setAttribute("data-trilium-task-state", value, element);
} else {
- writer.removeAttribute("data-task-state", element);
+ writer.removeAttribute("data-trilium-task-state", element);
}
}
});
editor.conversion.for("upcast").attributeToAttribute({
- view: {key: "data-task-state"},
+ view: {key: "data-trilium-task-state"},
model: {
key: TASK_STATE_ATTRIBUTE,
value: (viewElement: ViewElement) => {
- const value = viewElement.getAttribute("data-task-state");
+ const value = viewElement.getAttribute("data-trilium-task-state");
return typeof value === "string" && stateByName.has(value) && !isAnchorState(value)
? value
: null;
diff --git a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_ui.ts b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_ui.ts
index 97f1287325..7b0420615d 100644
--- a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_ui.ts
+++ b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_ui.ts
@@ -22,13 +22,13 @@ export default class TodoListMultistateUI extends Plugin {
});
// A checkbox preview inside the button, styled by the same
- // `[data-task-state]` CSS that decorates the real checkboxes.
+ // `[data-trilium-task-state]` CSS that decorates the real checkboxes.
const preview = new View(locale);
preview.setTemplate({
tag: "div",
attributes: {
class: "tn-task-checkbox ck-reset_all-excluded",
- "data-task-state": state.name
+ "data-trilium-task-state": state.name
}
});
button.children.add(preview);
diff --git a/packages/commons/src/lib/markdown_renderer.ts b/packages/commons/src/lib/markdown_renderer.ts
index 71e119a6da..2c7f5bcaae 100644
--- a/packages/commons/src/lib/markdown_renderer.ts
+++ b/packages/commons/src/lib/markdown_renderer.ts
@@ -297,7 +297,7 @@ export class CustomMarkdownRenderer extends Renderer {
override listitem(item: Tokens.ListItem): string {
if (item.task) {
const taskState = (item as TaskListItem)._taskState;
- const dataAttr = taskState ? ` data-task-state="${taskState}"` : "";
+ const dataAttr = taskState ? ` data-trilium-task-state="${taskState}"` : "";
let itemBody = "";
const checkbox = this.checkbox({ checked: !!item.checked, raw: "- [ ]", type: "checkbox" });
if (item.loose) {
diff --git a/packages/commons/src/lib/task_states.ts b/packages/commons/src/lib/task_states.ts
index 314c460b61..9741d387ca 100644
--- a/packages/commons/src/lib/task_states.ts
+++ b/packages/commons/src/lib/task_states.ts
@@ -7,7 +7,7 @@
* customizable states for toolbar order and keyboard cycling.
*/
export interface TaskStateDef {
- /** The `stateName` label value — used verbatim as the `data-task-state` attribute. */
+ /** The `stateName` label value — used verbatim as the `data-trilium-task-state` attribute. */
name: string;
/** Human-readable display name (the state note's title). */
title: string;
diff --git a/packages/trilium-core/src/services/export/markdown.spec.ts b/packages/trilium-core/src/services/export/markdown.spec.ts
index 26e881b4dd..3e2f7f45b8 100644
--- a/packages/trilium-core/src/services/export/markdown.spec.ts
+++ b/packages/trilium-core/src/services/export/markdown.spec.ts
@@ -348,25 +348,25 @@ describe("Markdown export", () => {
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
- it("exports todo list multistate markers from data-task-state", () => {
+ it("exports todo list multistate markers from data-trilium-task-state", () => {
const html = trimIndentation/*html*/`\
<ul class="todo-list">
- <li data-task-state="doing">
+ <li data-trilium-task-state="doing">
<label class="todo-list__label">
<input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Doing</span>
</label>
</li>
- <li data-task-state="done">
+ <li data-trilium-task-state="done">
<label class="todo-list__label">
<input type="checkbox" checked="checked" disabled="disabled"><span class="todo-list__label__description">Done</span>
</label>
</li>
- <li data-task-state="cancelled">
+ <li data-trilium-task-state="cancelled">
<label class="todo-list__label">
<input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Cancelled</span>
</label>
</li>
- <li data-task-state="maybe">
+ <li data-trilium-task-state="maybe">
<label class="todo-list__label">
<input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Maybe</span>
</label>
diff --git a/packages/trilium-core/src/services/export/markdown.ts b/packages/trilium-core/src/services/export/markdown.ts
index 9e98948146..882e72003f 100644
--- a/packages/trilium-core/src/services/export/markdown.ts
+++ b/packages/trilium-core/src/services/export/markdown.ts
@@ -233,7 +233,7 @@ function buildListItemFilter(): Rule {
const index = Array.prototype.indexOf.call(parent.children, node);
prefix = `${start ? Number(start) + index : index + 1}. `;
} else if (parent.classList.contains("todo-list")) {
- const state = (node as HTMLElement).getAttribute("data-task-state");
+ const state = (node as HTMLElement).getAttribute("data-trilium-task-state");
const stateMarker = state
? currentTaskStates.find((s) => s.name === state)?.markdownSymbol
: undefined;
diff --git a/packages/trilium-core/src/services/import/markdown.spec.ts b/packages/trilium-core/src/services/import/markdown.spec.ts
index 4bdaa86c4c..d206c944b7 100644
--- a/packages/trilium-core/src/services/import/markdown.spec.ts
+++ b/packages/trilium-core/src/services/import/markdown.spec.ts
@@ -284,16 +284,16 @@ $$`;
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
});
- it("imports todo list multistate markers as data-task-state", () => {
+ it("imports todo list multistate markers as data-trilium-task-state", () => {
const input = trimIndentation`\
- [/] Doing
- [-] Cancelled
- [?] Maybe`;
const expected = [
`<ul class="todo-list">`,
- `<li data-task-state="doing"><label class="todo-list__label"><input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Doing</span></label></li>`,
- `<li data-task-state="cancelled"><label class="todo-list__label"><input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Cancelled</span></label></li>`,
- `<li data-task-state="maybe"><label class="todo-list__label"><input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Maybe</span></label></li>`,
+ `<li data-trilium-task-state="doing"><label class="todo-list__label"><input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Doing</span></label></li>`,
+ `<li data-trilium-task-state="cancelled"><label class="todo-list__label"><input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Cancelled</span></label></li>`,
+ `<li data-trilium-task-state="maybe"><label class="todo-list__label"><input type="checkbox" disabled="disabled"><span class="todo-list__label__description">Maybe</span></label></li>`,
`</ul>`
].join("");
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
diff --git a/packages/trilium-core/src/services/task_states.ts b/packages/trilium-core/src/services/task_states.ts
index b29a5c8869..f1ca4e1ddf 100644
--- a/packages/trilium-core/src/services/task_states.ts
+++ b/packages/trilium-core/src/services/task_states.ts
@@ -136,7 +136,7 @@ function resolveIconGlyph(iconClass: string): {glyph: string; fontFamily: string
}
/**
- * Generates the CSS that renders each task state's icon on its `data-task-state`
+ * Generates the CSS that renders each task state's icon on its `data-trilium-task-state`
* checkbox. Resolution is a plain manifest lookup, so this works server-side and
* the same stylesheet can be served to both the app and shared notes.
*/
@@ -150,7 +150,7 @@ export function generateTaskStateCss(): string {
if (!resolved) {
continue;
}
- const selector = `li[data-task-state="${escapeCssString(state.name)}"], .tn-task-checkbox[data-task-state="${escapeCssString(state.name)}"]`;
+ const selector = `li[data-trilium-task-state="${escapeCssString(state.name)}"], .tn-task-checkbox[data-trilium-task-state="${escapeCssString(state.name)}"]`;
rules.push(`${selector} {
--task-state-glyph: "${resolved.glyph}";
--task-state-glyph-font-family: "${resolved.fontFamily}";