diff options
author | Unknwon <u@gogs.io> | 2017-03-31 18:14:40 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-05-17 18:46:23 -0400 |
commit | 1b5a418fd33010a5b41994797f636d822904d51b (patch) | |
tree | fe48091c1351c4f808ca6b8566fe9330ea4dbb56 /pkg/markup | |
parent | a11044f78954f5c173d686cd46833386cc43bc16 (diff) |
modules/markup: initial support for org-mode (#4373)
Diffstat (limited to 'pkg/markup')
-rw-r--r-- | pkg/markup/markdown.go | 2 | ||||
-rw-r--r-- | pkg/markup/markup.go | 22 |
2 files changed, 20 insertions, 4 deletions
diff --git a/pkg/markup/markdown.go b/pkg/markup/markdown.go index 741f6f55..55e40dc3 100644 --- a/pkg/markup/markdown.go +++ b/pkg/markup/markdown.go @@ -116,7 +116,7 @@ func (options *MarkdownRenderer) ListItem(out *bytes.Buffer, text []byte, flags options.Renderer.ListItem(out, text, flags) } -// RawMarkdown renders Markdown to HTML without handling special links. +// RawMarkdown renders content in Markdown syntax to HTML without handling special links. func RawMarkdown(body []byte, urlPrefix string) []byte { htmlFlags := 0 htmlFlags |= blackfriday.HTML_SKIP_STYLE diff --git a/pkg/markup/markup.go b/pkg/markup/markup.go index 6173be39..d043a993 100644 --- a/pkg/markup/markup.go +++ b/pkg/markup/markup.go @@ -308,11 +308,26 @@ OUTER_LOOP: type Type string const ( - UNRECOGNIZED Type = "unrecognized" - MARKDOWN Type = "markdown" - ORG_MODE Type = "orgmode" + UNRECOGNIZED Type = "unrecognized" + MARKDOWN Type = "markdown" + ORG_MODE Type = "orgmode" + IPYTHON_NOTEBOOK Type = "ipynb" ) +// Detect returns best guess of a markup type based on file name. +func Detect(filename string) Type { + switch { + case IsMarkdownFile(filename): + return MARKDOWN + case IsOrgModeFile(filename): + return ORG_MODE + case IsIPythonNotebook(filename): + return IPYTHON_NOTEBOOK + default: + return UNRECOGNIZED + } +} + // Render takes a string or []byte and renders to HTML in given type of syntax with special links. func Render(typ Type, input interface{}, urlPrefix string, metas map[string]string) []byte { var rawBytes []byte @@ -331,6 +346,7 @@ func Render(typ Type, input interface{}, urlPrefix string, metas map[string]stri case MARKDOWN: rawHTML = RawMarkdown(rawBytes, urlPrefix) case ORG_MODE: + rawHTML = RawOrgMode(rawBytes, urlPrefix) default: return rawBytes // Do nothing if syntax type is not recognized } |