]> source.dussan.org Git - gitea.git/commitdiff
Render plaintext task list items for markdown files (#26186)
authorEarl Warren <109468362+earl-warren@users.noreply.github.com>
Thu, 27 Jul 2023 14:15:31 +0000 (16:15 +0200)
committerGitHub <noreply@github.com>
Thu, 27 Jul 2023 14:15:31 +0000 (14:15 +0000)
- The library that's being used for org-mode, [doesn't render the status
of list items](https://github.com/niklasfasching/go-org/issues/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 <postmaster@gusted.xyz>
modules/markup/sanitizer.go
modules/markup/sanitizer_test.go
web_src/css/markup/content.css

index 9f97f1d5b13e0c5d42fb2744136f3ed0d703bb15..48c08831f1661311565f40c219d7199b3bcd470a 100644 (file)
@@ -96,6 +96,9 @@ func createDefaultPolicy() *bluemonday.Policy {
        // Allow classes for task lists
        policy.AllowAttrs("class").Matching(regexp.MustCompile(`task-list-item`)).OnElements("li")
 
+       // Allow classes for org mode list item status.
+       policy.AllowAttrs("class").Matching(regexp.MustCompile(`^(unchecked|checked|indeterminate)$`)).OnElements("li")
+
        // Allow icons
        policy.AllowAttrs("class").Matching(regexp.MustCompile(`^icon(\s+[\p{L}\p{N}_-]+)+$`)).OnElements("i")
 
index 4d85cbf9f303bcdc75e08f9b9a340ca7f23e99f2..0bc63ff0a7cb3002049f64329cec278ee430c0c4 100644 (file)
@@ -53,6 +53,11 @@ func Test_Sanitizer(t *testing.T) {
                `<p style="bad-color: red">Hello World</p>`, `<p>Hello World</p>`,
                `<code style="bad-color: red">Hello World</code>`, `<code>Hello World</code>`,
 
+               // Org mode status of list items.
+               `<li class="checked"></li>`, `<li class="checked"></li>`,
+               `<li class="unchecked"></li>`, `<li class="unchecked"></li>`,
+               `<li class="indeterminate"></li>`, `<li class="indeterminate"></li>`,
+
                // URLs
                `<a href="cbthunderlink://somebase64string)">my custom URL scheme</a>`, `<a href="cbthunderlink://somebase64string)" rel="nofollow">my custom URL scheme</a>`,
                `<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>`,
index 2a645e522a174d5bbf74439dcd856d081e21cfaa..d89e02c6404f42f8f58f899257103c3daf0777a0 100644 (file)
   border-top-left-radius: 0 !important;
   border-top-right-radius: 0 !important;
 }
+
+.file-view.markup.orgmode li.unchecked::before {
+  content: "[ ] ";
+}
+
+.file-view.markup.orgmode li.checked::before {
+  content: "[x] ";
+}
+
+.file-view.markup.orgmode li.indeterminate::before {
+  content: "[-] ";
+}
+
+/* This is only needed for <p> because they are literally acting as paragraphs,
+ * and thus having an ::before on the same line would force the paragraph to
+ * move to the next line. This can be avoided by an inline-block display that
+ * avoids that property while still having the other properties of the block
+ * display. */
+.file-view.markup.orgmode li.unchecked > p,
+.file-view.markup.orgmode li.checked > p,
+.file-view.markup.orgmode li.indeterminate > p {
+  display: inline-block;
+}