Skip to content

Commit eaea530

Browse files
earl-warrenGusted
andauthored
Render plaintext task list items for markdown files (#26186)
- The library that's being used for org-mode, [doesn't render the status of list items](niklasfasching/go-org#63). - Add a modified version of the proposed CSS snippet to still display the status for the list items. The alternative was parsing HTML and transforming it, which is too complicated for this small task. - Resolves https://codeberg.org/Codeberg/Community/issues/1099 (cherry picked from commit 9753c7e4b8490b8f1e3d19cb06187503b88afb88) Refs: https://codeberg.org/forgejo/forgejo/pulls/1071 Co-authored-by: Gusted <[email protected]>
1 parent 16afe4f commit eaea530

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

modules/markup/sanitizer.go

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func createDefaultPolicy() *bluemonday.Policy {
9696
// Allow classes for task lists
9797
policy.AllowAttrs("class").Matching(regexp.MustCompile(`task-list-item`)).OnElements("li")
9898

99+
// Allow classes for org mode list item status.
100+
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^(unchecked|checked|indeterminate)$`)).OnElements("li")
101+
99102
// Allow icons
100103
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^icon(\s+[\p{L}\p{N}_-]+)+$`)).OnElements("i")
101104

modules/markup/sanitizer_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func Test_Sanitizer(t *testing.T) {
5353
`<p style="bad-color: red">Hello World</p>`, `<p>Hello World</p>`,
5454
`<code style="bad-color: red">Hello World</code>`, `<code>Hello World</code>`,
5555

56+
// Org mode status of list items.
57+
`<li class="checked"></li>`, `<li class="checked"></li>`,
58+
`<li class="unchecked"></li>`, `<li class="unchecked"></li>`,
59+
`<li class="indeterminate"></li>`, `<li class="indeterminate"></li>`,
60+
5661
// URLs
5762
`<a href="cbthunderlink://somebase64string)">my custom URL scheme</a>`, `<a href="cbthunderlink://somebase64string)" rel="nofollow">my custom URL scheme</a>`,
5863
`<a href="matrix:roomid/psumPMeAfzgAeQpXMG:feneas.org?action=join">my custom URL scheme</a>`, `<a href="matrix:roomid/psumPMeAfzgAeQpXMG:feneas.org?action=join" rel="nofollow">my custom URL scheme</a>`,

web_src/css/markup/content.css

+23
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,26 @@
556556
border-top-left-radius: 0 !important;
557557
border-top-right-radius: 0 !important;
558558
}
559+
560+
.file-view.markup.orgmode li.unchecked::before {
561+
content: "[ ] ";
562+
}
563+
564+
.file-view.markup.orgmode li.checked::before {
565+
content: "[x] ";
566+
}
567+
568+
.file-view.markup.orgmode li.indeterminate::before {
569+
content: "[-] ";
570+
}
571+
572+
/* This is only needed for <p> because they are literally acting as paragraphs,
573+
* and thus having an ::before on the same line would force the paragraph to
574+
* move to the next line. This can be avoided by an inline-block display that
575+
* avoids that property while still having the other properties of the block
576+
* display. */
577+
.file-view.markup.orgmode li.unchecked > p,
578+
.file-view.markup.orgmode li.checked > p,
579+
.file-view.markup.orgmode li.indeterminate > p {
580+
display: inline-block;
581+
}

0 commit comments

Comments
 (0)