Skip to content

Commit 1febcc4

Browse files
committed
make checkboxes work in markdown
1 parent 8fb9947 commit 1febcc4

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"prefer-template": "off",
2626
"no-await-in-loop": "off",
2727
"no-empty": "off",
28-
"no-nested-ternary": "off"
28+
"no-nested-ternary": "off",
29+
"prefer-arrow-callback": "off"
2930
}
3031
}

ui/src/elements/markdown-note.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { EntryRecord } from "@holochain-open-dev/utils";
22
import { consume } from "@lit/context";
3-
import { css, html, LitElement } from "lit";
3+
import { css, html, LitElement, PropertyValueMap } from "lit";
44
import { customElement, property, state } from "lit/decorators.js";
5+
56
import {
67
Workspace,
78
DocumentStore,
@@ -142,7 +143,7 @@ export class MarkdownNote extends LitElement {
142143
if (this._renderDrawer && this.drawer) {
143144
this.drawer.show()
144145
}
145-
}
146+
}
146147

147148
@state()
148149
_workspaceName: string = "main";

ui/src/utils.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,21 @@ Marked.setOptions
9696
smartypants: false
9797
});
9898

99+
Marked.setBlockRule(/\[([x ]*)\](.*)/, function x (execArr) {
100+
101+
// Don't use arrow function for this callback
102+
// if you need Renderer's context, for example to `this.options`.
103+
if (execArr) {
104+
const checked = execArr[1];
105+
const text = execArr[2];
106+
return `<input type="checkbox" ${checked === "x" ?"checked":""}>${text}</input>`
107+
}
108+
109+
return `<input type="checkbox"></input>`
110+
});
111+
99112
export function sortByDescendantTimestamp(
100113
notes: EntryRecord<Document>[]
101114
): Array<EntryRecord<Document>> {
102115
return notes.sort((a, b) => b.action.timestamp - a.action.timestamp);
103116
}
104-

0 commit comments

Comments
 (0)