orgmode.go 1010 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2017 The Gogs 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. "path/filepath"
  7. "strings"
  8. "github.com/chaseadamsio/goorgeous"
  9. )
  10. var orgModeExtensions = []string{".org"}
  11. // IsOrgModeFile reports whether name looks like a Org-mode file based on its extension.
  12. func IsOrgModeFile(name string) bool {
  13. extension := strings.ToLower(filepath.Ext(name))
  14. for _, ext := range orgModeExtensions {
  15. if strings.ToLower(ext) == extension {
  16. return true
  17. }
  18. }
  19. return false
  20. }
  21. // RawOrgMode renders content in Org-mode syntax to HTML without handling special links.
  22. func RawOrgMode(body []byte, urlPrefix string) []byte {
  23. return goorgeous.OrgCommon(body)
  24. }
  25. // OrgMode takes a string or []byte and renders to HTML in Org-mode syntax with special links.
  26. func OrgMode(input interface{}, urlPrefix string, metas map[string]string) []byte {
  27. return Render(ORG_MODE, input, urlPrefix, metas)
  28. }