gitea源码

finalprocessor.go 743B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package internal
  4. import (
  5. "bytes"
  6. "io"
  7. )
  8. type finalProcessor struct {
  9. renderInternal *RenderInternal
  10. output io.Writer
  11. buf bytes.Buffer
  12. }
  13. func (p *finalProcessor) Write(data []byte) (int, error) {
  14. p.buf.Write(data)
  15. return len(data), nil
  16. }
  17. func (p *finalProcessor) Close() error {
  18. // TODO: reading the whole markdown isn't a problem at the moment,
  19. // because "postProcess" already does so. In the future we could optimize the code to process data on the fly.
  20. buf := p.buf.Bytes()
  21. buf = bytes.ReplaceAll(buf, []byte(` data-attr-class="`+p.renderInternal.secureIDPrefix), []byte(` class="`))
  22. _, err := p.output.Write(buf)
  23. return err
  24. }