aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup/internal/finalprocessor.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-11-18 13:25:42 +0800
committerGitHub <noreply@github.com>2024-11-18 13:25:42 +0800
commit8a20fba8eb1ac01a0de9355eff84af69d4636d96 (patch)
treebf37fa52f688a31b6cf8d4879438020b108235cc /modules/markup/internal/finalprocessor.go
parent4f879a00df029e09b40f64bf8de0572704766115 (diff)
downloadgitea-8a20fba8eb1ac01a0de9355eff84af69d4636d96.tar.gz
gitea-8a20fba8eb1ac01a0de9355eff84af69d4636d96.zip
Refactor markup render system (#32533)
Remove unmaintainable sanitizer rules. No need to add special "class" regexp rules anymore, use RenderInternal.SafeAttr instead, more details (and examples) are in the tests
Diffstat (limited to 'modules/markup/internal/finalprocessor.go')
-rw-r--r--modules/markup/internal/finalprocessor.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/markup/internal/finalprocessor.go b/modules/markup/internal/finalprocessor.go
new file mode 100644
index 0000000000..14d46a161f
--- /dev/null
+++ b/modules/markup/internal/finalprocessor.go
@@ -0,0 +1,30 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package internal
+
+import (
+ "bytes"
+ "io"
+)
+
+type finalProcessor struct {
+ renderInternal *RenderInternal
+
+ output io.Writer
+ buf bytes.Buffer
+}
+
+func (p *finalProcessor) Write(data []byte) (int, error) {
+ p.buf.Write(data)
+ return len(data), nil
+}
+
+func (p *finalProcessor) Close() error {
+ // TODO: reading the whole markdown isn't a problem at the moment,
+ // because "postProcess" already does so. In the future we could optimize the code to process data on the fly.
+ buf := p.buf.Bytes()
+ buf = bytes.ReplaceAll(buf, []byte(` data-attr-class="`+p.renderInternal.secureIDPrefix), []byte(` class="`))
+ _, err := p.output.Write(buf)
+ return err
+}