Fix and refactor markdown rendering (#32522)
This commit is contained in:
parent
e546480d0a
commit
5eebe1dc5f
27 changed files with 289 additions and 278 deletions
|
@ -27,15 +27,6 @@ const (
|
|||
RenderMetaAsTable RenderMetaMode = "table"
|
||||
)
|
||||
|
||||
type RenderContentMode string
|
||||
|
||||
const (
|
||||
RenderContentAsDefault RenderContentMode = "" // empty means "default", no special handling, maybe just a simple "document"
|
||||
RenderContentAsComment RenderContentMode = "comment"
|
||||
RenderContentAsTitle RenderContentMode = "title"
|
||||
RenderContentAsWiki RenderContentMode = "wiki"
|
||||
)
|
||||
|
||||
var RenderBehaviorForTesting struct {
|
||||
// Markdown line break rendering has 2 default behaviors:
|
||||
// * Use hard: replace "\n" with "<br>" for comments, setting.Markdown.EnableHardLineBreakInComments=true
|
||||
|
@ -59,12 +50,14 @@ type RenderContext struct {
|
|||
// for file mode, it could be left as empty, and will be detected by file extension in RelativePath
|
||||
MarkupType string
|
||||
|
||||
// what the content will be used for: eg: for comment or for wiki? or just render a file?
|
||||
ContentMode RenderContentMode
|
||||
Links Links // special link references for rendering, especially when there is a branch/tree path
|
||||
|
||||
// user&repo, format&style®exp (for external issue pattern), teams&org (for mention)
|
||||
// BranchNameSubURL (for iframe&asciicast)
|
||||
// markupAllowShortIssuePattern, markupContentMode (wiki)
|
||||
// markdownLineBreakStyle (comment, document)
|
||||
Metas map[string]string
|
||||
|
||||
Links Links // special link references for rendering, especially when there is a branch/tree path
|
||||
Metas map[string]string // user&repo, format&style®exp (for external issue pattern), teams&org (for mention), BranchNameSubURL(for iframe&asciicast)
|
||||
DefaultLink string // TODO: need to figure out
|
||||
GitRepo *git.Repository
|
||||
Repo gitrepo.Repository
|
||||
ShaExistCache map[string]bool
|
||||
|
@ -102,6 +95,10 @@ func (ctx *RenderContext) AddCancel(fn func()) {
|
|||
}
|
||||
}
|
||||
|
||||
func (ctx *RenderContext) IsMarkupContentWiki() bool {
|
||||
return ctx.Metas != nil && ctx.Metas["markupContentMode"] == "wiki"
|
||||
}
|
||||
|
||||
// Render renders markup file to HTML with all specific handling stuff.
|
||||
func Render(ctx *RenderContext, input io.Reader, output io.Writer) error {
|
||||
if ctx.MarkupType == "" && ctx.RelativePath != "" {
|
||||
|
@ -232,3 +229,7 @@ func Init(ph *ProcessorHelper) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ComposeSimpleDocumentMetas() map[string]string {
|
||||
return map[string]string{"markdownLineBreakStyle": "document"}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue