1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-20 05:39:42 +02:00
documize/domain/section/markdown/markdown.go

62 lines
1.6 KiB
Go
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
package markdown
import (
"net/http"
"github.com/documize/blackfriday"
2017-07-21 13:39:53 +01:00
"github.com/documize/community/core/env"
"github.com/documize/community/domain/section/provider"
"github.com/documize/community/domain/store"
2019-11-19 11:47:51 +00:00
"github.com/microcosm-cc/bluemonday"
2016-07-07 18:54:16 -07:00
)
// Provider represents Markdown
type Provider struct {
2017-08-02 15:26:31 +01:00
Runtime *env.Runtime
Store *store.Store
2016-07-07 18:54:16 -07:00
}
// Meta describes us
func (*Provider) Meta() provider.TypeMeta {
section := provider.TypeMeta{}
section.ID = "1470bb4a-36c6-4a98-a443-096f5658378b"
section.Title = "Markdown"
section.Description = "CommonMark based content"
2016-07-07 18:54:16 -07:00
section.ContentType = "markdown"
2016-11-09 15:16:44 -08:00
section.PageType = "section"
2016-07-07 18:54:16 -07:00
section.Order = 9998
return section
}
// Command stub.
func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
provider.WriteEmpty(w)
}
// Render converts markdown data into HTML suitable for browser rendering.
func (*Provider) Render(ctx *provider.Context, config, data string) string {
2019-11-19 11:47:51 +00:00
unsafe := blackfriday.Run([]byte(data))
2016-07-07 18:54:16 -07:00
2019-11-19 11:47:51 +00:00
safe := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
return string(safe)
2016-07-07 18:54:16 -07:00
}
// Refresh just sends back data as-is.
func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
return data
}