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:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-07-10 13:52:20 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-07-10 13:52:20 +0300
commit00d70e55692a75147bfa0ba73f21f6228a8a1934 (patch)
treef0204ff8afd5103096de192c6ed4f3b97e2d269c /helpers
parent068a77151e27adb4106e86c407831ad6aa34ad8d (diff)
Remove []byte to string to []byte conversion in Rst
Diffstat (limited to 'helpers')
-rw-r--r--helpers/content.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/helpers/content.go b/helpers/content.go
index 47a72ffb9..6da437b3d 100644
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -373,7 +373,7 @@ func RenderBytes(ctx *RenderingContext) []byte {
case "mmark":
return mmarkRender(ctx)
case "rst":
- return []byte(getRstContent(ctx.Content))
+ return getRstContent(ctx.Content)
}
}
@@ -503,7 +503,7 @@ func getRstExecPath() string {
// getRstContent calls the Python script rst2html as an external helper
// to convert reStructuredText content to HTML.
-func getRstContent(content []byte) string {
+func getRstContent(content []byte) []byte {
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
path := getRstExecPath()
@@ -511,7 +511,7 @@ func getRstContent(content []byte) string {
if path == "" {
jww.ERROR.Println("rst2html / rst2html.py not found in $PATH: Please install.\n",
" Leaving reStructuredText content unrendered.")
- return (string(content))
+ return content
}
@@ -523,11 +523,11 @@ func getRstContent(content []byte) string {
jww.ERROR.Println(err)
}
- rstLines := strings.Split(out.String(), "\n")
- for i, line := range rstLines {
- if strings.HasPrefix(line, "<body>") {
- rstLines = (rstLines[i+1 : len(rstLines)-3])
- }
- }
- return strings.Join(rstLines, "\n")
+ result := out.Bytes()
+
+ // TODO(bep) check if rst2html has a body only option.
+ bodyStart := bytes.Index(result, []byte("<body>\n"))
+ bodyEnd := bytes.Index(result, []byte("\n</body>"))
+
+ return result[bodyStart+7 : bodyEnd]
}