From eaea530d6bc84b23e6ff14ff8c2a74aa3b67ecd0 Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Thu, 27 Jul 2023 16:15:31 +0200 Subject: 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](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 --- modules/markup/sanitizer.go | 3 +++ modules/markup/sanitizer_test.go | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'modules/markup') diff --git a/modules/markup/sanitizer.go b/modules/markup/sanitizer.go index 9f97f1d5b1..48c08831f1 100644 --- a/modules/markup/sanitizer.go +++ b/modules/markup/sanitizer.go @@ -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") diff --git a/modules/markup/sanitizer_test.go b/modules/markup/sanitizer_test.go index 4d85cbf9f3..0bc63ff0a7 100644 --- a/modules/markup/sanitizer_test.go +++ b/modules/markup/sanitizer_test.go @@ -53,6 +53,11 @@ func Test_Sanitizer(t *testing.T) { `

Hello World

`, `

Hello World

`, `Hello World`, `Hello World`, + // Org mode status of list items. + `
  • `, `
  • `, + `
  • `, `
  • `, + `
  • `, `
  • `, + // URLs `my custom URL scheme`, `my custom URL scheme`, `my custom URL scheme`, `my custom URL scheme`, -- cgit v1.2.3