You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

orgmode.go 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package markup
  5. import (
  6. "code.gitea.io/gitea/modules/markup"
  7. "code.gitea.io/gitea/modules/markup/markdown"
  8. "github.com/chaseadamsio/goorgeous"
  9. "github.com/russross/blackfriday"
  10. )
  11. func init() {
  12. markup.RegisterParser(Parser{})
  13. }
  14. // Parser implements markup.Parser for orgmode
  15. type Parser struct {
  16. }
  17. // Name implements markup.Parser
  18. func (Parser) Name() string {
  19. return "orgmode"
  20. }
  21. // Extensions implements markup.Parser
  22. func (Parser) Extensions() []string {
  23. return []string{".org"}
  24. }
  25. // Render renders orgmode rawbytes to HTML
  26. func Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
  27. htmlFlags := blackfriday.HTML_USE_XHTML
  28. htmlFlags |= blackfriday.HTML_SKIP_STYLE
  29. htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
  30. renderer := &markdown.Renderer{
  31. Renderer: blackfriday.HtmlRenderer(htmlFlags, "", ""),
  32. URLPrefix: urlPrefix,
  33. IsWiki: isWiki,
  34. }
  35. result := goorgeous.Org(rawBytes, renderer)
  36. return result
  37. }
  38. // RenderString reners orgmode string to HTML string
  39. func RenderString(rawContent string, urlPrefix string, metas map[string]string, isWiki bool) string {
  40. return string(Render([]byte(rawContent), urlPrefix, metas, isWiki))
  41. }
  42. // Render implements markup.Parser
  43. func (Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
  44. return Render(rawBytes, urlPrefix, metas, isWiki)
  45. }