github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/core/section/markdown/markdown.go (about)

     1  // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
     2  //
     3  // This software (Documize Community Edition) is licensed under
     4  // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
     5  //
     6  // You can operate outside the AGPL restrictions by purchasing
     7  // Documize Enterprise Edition and obtaining a commercial license
     8  // by contacting <sales@documize.com>.
     9  //
    10  // https://documize.com
    11  
    12  package markdown
    13  
    14  import (
    15  	"net/http"
    16  
    17  	"github.com/documize/blackfriday"
    18  	"github.com/documize/community/core/section/provider"
    19  )
    20  
    21  // Provider represents Markdown
    22  type Provider struct {
    23  }
    24  
    25  // Meta describes us
    26  func (*Provider) Meta() provider.TypeMeta {
    27  	section := provider.TypeMeta{}
    28  
    29  	section.ID = "1470bb4a-36c6-4a98-a443-096f5658378b"
    30  	section.Title = "Markdown"
    31  	section.Description = "CommonMark based content"
    32  	section.ContentType = "markdown"
    33  	section.PageType = "section"
    34  	section.Order = 9998
    35  
    36  	return section
    37  }
    38  
    39  // Command stub.
    40  func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
    41  	provider.WriteEmpty(w)
    42  }
    43  
    44  // Render converts markdown data into HTML suitable for browser rendering.
    45  func (*Provider) Render(ctx *provider.Context, config, data string) string {
    46  	result := blackfriday.MarkdownCommon([]byte(data))
    47  
    48  	return string(result)
    49  }
    50  
    51  // Refresh just sends back data as-is.
    52  func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
    53  	return data
    54  }