orgmode.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package markup
  2. import (
  3. "path/filepath"
  4. "strings"
  5. "github.com/chaseadamsio/goorgeous"
  6. log "gopkg.in/clog.v1"
  7. )
  8. var orgModeExtensions = []string{".org"}
  9. // IsOrgModeFile reports whether name looks like a Org-mode file based on its extension.
  10. func IsOrgModeFile(name string) bool {
  11. extension := strings.ToLower(filepath.Ext(name))
  12. for _, ext := range orgModeExtensions {
  13. if strings.ToLower(ext) == extension {
  14. return true
  15. }
  16. }
  17. return false
  18. }
  19. // RawOrgMode renders content in Org-mode syntax to HTML without handling special links.
  20. func RawOrgMode(body []byte, urlPrefix string) (result []byte) {
  21. // TODO: remove recover code once the third-party package is stable
  22. defer func() {
  23. if err := recover(); err != nil {
  24. result = body
  25. log.Warn("PANIC (RawOrgMode): %v", err)
  26. }
  27. }()
  28. return goorgeous.OrgCommon(body)
  29. }
  30. // OrgMode takes a string or []byte and renders to HTML in Org-mode syntax with special links.
  31. func OrgMode(input interface{}, urlPrefix string, metas map[string]string) []byte {
  32. return Render(ORG_MODE, input, urlPrefix, metas)
  33. }