mirror of https://github.com/go-gitea/gitea.git
Add NeedPostProcess for Parser interface to improve performance of csv render (#15153)
This commit is contained in:
parent
bf3e584de2
commit
66f0fd0959
|
@ -831,12 +831,14 @@ Gitea can support Markup using external tools. The example below will add a mark
|
||||||
```ini
|
```ini
|
||||||
[markup.asciidoc]
|
[markup.asciidoc]
|
||||||
ENABLED = true
|
ENABLED = true
|
||||||
|
NEED_POSTPROCESS = true
|
||||||
FILE_EXTENSIONS = .adoc,.asciidoc
|
FILE_EXTENSIONS = .adoc,.asciidoc
|
||||||
RENDER_COMMAND = "asciidoc --out-file=- -"
|
RENDER_COMMAND = "asciidoc --out-file=- -"
|
||||||
IS_INPUT_FILE = false
|
IS_INPUT_FILE = false
|
||||||
```
|
```
|
||||||
|
|
||||||
- ENABLED: **false** Enable markup support; set to **true** to enable this renderer.
|
- ENABLED: **false** Enable markup support; set to **true** to enable this renderer.
|
||||||
|
- NEED\_POSTPROCESS: **true** set to **true** to replace links / sha1 and etc.
|
||||||
- FILE\_EXTENSIONS: **\<empty\>** List of file extensions that should be rendered by an external
|
- FILE\_EXTENSIONS: **\<empty\>** List of file extensions that should be rendered by an external
|
||||||
command. Multiple extentions needs a comma as splitter.
|
command. Multiple extentions needs a comma as splitter.
|
||||||
- RENDER\_COMMAND: External command to render all matching extensions.
|
- RENDER\_COMMAND: External command to render all matching extensions.
|
||||||
|
|
|
@ -297,12 +297,14 @@ test01.xls: application/vnd.ms-excel; charset=binary
|
||||||
```ini
|
```ini
|
||||||
[markup.asciidoc]
|
[markup.asciidoc]
|
||||||
ENABLED = false
|
ENABLED = false
|
||||||
|
NEED_POSTPROCESS = true
|
||||||
FILE_EXTENSIONS = .adoc,.asciidoc
|
FILE_EXTENSIONS = .adoc,.asciidoc
|
||||||
RENDER_COMMAND = "asciidoc --out-file=- -"
|
RENDER_COMMAND = "asciidoc --out-file=- -"
|
||||||
IS_INPUT_FILE = false
|
IS_INPUT_FILE = false
|
||||||
```
|
```
|
||||||
|
|
||||||
- ENABLED: 是否启用,默认为false。
|
- ENABLED: 是否启用,默认为false。
|
||||||
|
- NEED\_POSTPROCESS: **true** 设置为 true 则会替换渲染文件中的内部链接和Commit ID 等。
|
||||||
- FILE_EXTENSIONS: 关联的文档的扩展名,多个扩展名用都好分隔。
|
- FILE_EXTENSIONS: 关联的文档的扩展名,多个扩展名用都好分隔。
|
||||||
- RENDER_COMMAND: 工具的命令行命令及参数。
|
- RENDER_COMMAND: 工具的命令行命令及参数。
|
||||||
- IS_INPUT_FILE: 输入方式是最后一个参数为文件路径还是从标准输入读取。
|
- IS_INPUT_FILE: 输入方式是最后一个参数为文件路径还是从标准输入读取。
|
||||||
|
|
|
@ -28,6 +28,9 @@ func (Parser) Name() string {
|
||||||
return "csv"
|
return "csv"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NeedPostProcess implements markup.Parser
|
||||||
|
func (Parser) NeedPostProcess() bool { return false }
|
||||||
|
|
||||||
// Extensions implements markup.Parser
|
// Extensions implements markup.Parser
|
||||||
func (Parser) Extensions() []string {
|
func (Parser) Extensions() []string {
|
||||||
return []string{".csv", ".tsv"}
|
return []string{".csv", ".tsv"}
|
||||||
|
|
|
@ -38,6 +38,11 @@ func (p *Parser) Name() string {
|
||||||
return p.MarkupName
|
return p.MarkupName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NeedPostProcess implements markup.Parser
|
||||||
|
func (p *Parser) NeedPostProcess() bool {
|
||||||
|
return p.MarkupParser.NeedPostProcess
|
||||||
|
}
|
||||||
|
|
||||||
// Extensions returns the supported extensions of the tool
|
// Extensions returns the supported extensions of the tool
|
||||||
func (p *Parser) Extensions() []string {
|
func (p *Parser) Extensions() []string {
|
||||||
return p.FileExtensions
|
return p.FileExtensions
|
||||||
|
|
|
@ -228,6 +228,9 @@ func (Parser) Name() string {
|
||||||
return MarkupName
|
return MarkupName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NeedPostProcess implements markup.Parser
|
||||||
|
func (Parser) NeedPostProcess() bool { return true }
|
||||||
|
|
||||||
// Extensions implements markup.Parser
|
// Extensions implements markup.Parser
|
||||||
func (Parser) Extensions() []string {
|
func (Parser) Extensions() []string {
|
||||||
return setting.Markdown.FileExtensions
|
return setting.Markdown.FileExtensions
|
||||||
|
|
|
@ -33,6 +33,7 @@ func Init() {
|
||||||
type Parser interface {
|
type Parser interface {
|
||||||
Name() string // markup format name
|
Name() string // markup format name
|
||||||
Extensions() []string
|
Extensions() []string
|
||||||
|
NeedPostProcess() bool
|
||||||
Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte
|
Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,11 +83,14 @@ func RenderWiki(filename string, rawBytes []byte, urlPrefix string, metas map[st
|
||||||
|
|
||||||
func render(parser Parser, rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
|
func render(parser Parser, rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
|
||||||
result := parser.Render(rawBytes, urlPrefix, metas, isWiki)
|
result := parser.Render(rawBytes, urlPrefix, metas, isWiki)
|
||||||
|
if parser.NeedPostProcess() {
|
||||||
|
var err error
|
||||||
// TODO: one day the error should be returned.
|
// TODO: one day the error should be returned.
|
||||||
result, err := PostProcess(result, urlPrefix, metas, isWiki)
|
result, err = PostProcess(result, urlPrefix, metas, isWiki)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("PostProcess: %v", err)
|
log.Error("PostProcess: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return SanitizeBytes(result)
|
return SanitizeBytes(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ func (Parser) Name() string {
|
||||||
return "orgmode"
|
return "orgmode"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NeedPostProcess implements markup.Parser
|
||||||
|
func (Parser) NeedPostProcess() bool { return true }
|
||||||
|
|
||||||
// Extensions implements markup.Parser
|
// Extensions implements markup.Parser
|
||||||
func (Parser) Extensions() []string {
|
func (Parser) Extensions() []string {
|
||||||
return []string{".org"}
|
return []string{".org"}
|
||||||
|
|
|
@ -26,6 +26,7 @@ type MarkupParser struct {
|
||||||
Command string
|
Command string
|
||||||
FileExtensions []string
|
FileExtensions []string
|
||||||
IsInputFile bool
|
IsInputFile bool
|
||||||
|
NeedPostProcess bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkupSanitizerRule defines the policy for whitelisting attributes on
|
// MarkupSanitizerRule defines the policy for whitelisting attributes on
|
||||||
|
@ -129,5 +130,6 @@ func newMarkupRenderer(name string, sec *ini.Section) {
|
||||||
FileExtensions: exts,
|
FileExtensions: exts,
|
||||||
Command: command,
|
Command: command,
|
||||||
IsInputFile: sec.Key("IS_INPUT_FILE").MustBool(false),
|
IsInputFile: sec.Key("IS_INPUT_FILE").MustBool(false),
|
||||||
|
NeedPostProcess: sec.Key("NEED_POSTPROCESS").MustBool(true),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue