Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Fok <foka@debian.org>2015-01-21 16:05:16 +0300
committerAnthony Fok <foka@debian.org>2015-01-21 16:41:19 +0300
commit19c52ab0b5a5a8f89d43dcc2e2a15e2f53170017 (patch)
tree67caec1e7d94f74c7683cafba64734fb4635e897
parent1cc638693713d7f4ce564b91302af72e3d8531e2 (diff)
Register rstHandler to restore experimental reST support
(Experimental) reStructuredText support was working in v0.12, but was no longer handled after some refactoring in v0.13-DEV. That experimental support is now restored. Furthermore, check for both rst2html and rst2html.py in the PATH, and execute whichever is found. See #472 for more information.
-rw-r--r--helpers/content.go12
-rw-r--r--hugolib/handler_page.go28
2 files changed, 39 insertions, 1 deletions
diff --git a/helpers/content.go b/helpers/content.go
index e8c086a33..1d051801d 100644
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -252,7 +252,17 @@ func TruncateWordsToWholeSentence(s string, max int) string {
func GetRstContent(content []byte) string {
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
- cmd := exec.Command("rst2html.py", "--leave-comments")
+ path, err := exec.LookPath("rst2html")
+ if err != nil {
+ path, err = exec.LookPath("rst2html.py")
+ if err != nil {
+ jww.ERROR.Println("rst2html / rst2html.py not found in $PATH: Please install.\n",
+ " Leaving reStructuredText content unrendered.")
+ return(string(content))
+ }
+ }
+
+ cmd := exec.Command(path, "--leave-comments")
cmd.Stdin = bytes.NewReader(cleanContent)
var out bytes.Buffer
cmd.Stdout = &out
diff --git a/hugolib/handler_page.go b/hugolib/handler_page.go
index 73cd12a79..6c912ded3 100644
--- a/hugolib/handler_page.go
+++ b/hugolib/handler_page.go
@@ -24,6 +24,7 @@ func init() {
RegisterHandler(new(markdownHandler))
RegisterHandler(new(htmlHandler))
RegisterHandler(new(asciidocHandler))
+ RegisterHandler(new(rstHandler))
}
type basicPageHandler Handle
@@ -100,3 +101,30 @@ func (h asciidocHandler) PageConvert(p *Page, t tpl.Template) HandledResult {
//err := p.Convert()
return HandledResult{page: p, err: nil}
}
+
+type rstHandler struct {
+ basicPageHandler
+}
+
+func (h rstHandler) Extensions() []string { return []string{"rest", "rst"} }
+func (h rstHandler) PageConvert(p *Page, t tpl.Template) HandledResult {
+ p.ProcessShortcodes(t)
+
+ tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.renderContent(helpers.RemoveSummaryDivider(p.rawContent)))
+
+ if len(p.contentShortCodes) > 0 {
+ tmpContentWithTokensReplaced, err := replaceShortcodeTokens(tmpContent, shortcodePlaceholderPrefix, -1, true, p.contentShortCodes)
+
+ if err != nil {
+ jww.FATAL.Printf("Fail to replace short code tokens in %s:\n%s", p.BaseFileName(), err.Error())
+ return HandledResult{err: err}
+ } else {
+ tmpContent = tmpContentWithTokensReplaced
+ }
+ }
+
+ p.Content = helpers.BytesToHTML(tmpContent)
+ p.TableOfContents = helpers.BytesToHTML(tmpTableOfContents)
+
+ return HandledResult{err: nil}
+}