58 lines
2.2 KiB
Diff
58 lines
2.2 KiB
Diff
|
From b137ad4dbd6d14d0a9af68c044aaee61f2c87fe5 Mon Sep 17 00:00:00 2001
|
||
|
From: Shreyansh Khajanchi <shreyansh_k@live.com>
|
||
|
Date: Wed, 3 Oct 2018 19:45:54 +0530
|
||
|
Subject: [PATCH] helpers/content.go: call rst2html directly on *nix but via
|
||
|
python on windows
|
||
|
|
||
|
Initially, rst2html was called via the python interpreter which would
|
||
|
fail if the script was wrapped in a launcher as on NixOS.
|
||
|
Ideally, on *nix, binaries should be invoked directly to ensure that
|
||
|
shebangs work properly as is being done now.
|
||
|
Handle the case of windows as it doesn't do shebangs.
|
||
|
---
|
||
|
helpers/content.go | 17 ++++++++++++++---
|
||
|
1 file changed, 14 insertions(+), 3 deletions(-)
|
||
|
|
||
|
diff --git a/helpers/content.go b/helpers/content.go
|
||
|
index 55d8ce202..f8479cd1b 100644
|
||
|
--- a/helpers/content.go
|
||
|
+++ b/helpers/content.go
|
||
|
@@ -22,6 +22,7 @@ import (
|
||
|
"fmt"
|
||
|
"html/template"
|
||
|
"os/exec"
|
||
|
+ "runtime"
|
||
|
"unicode"
|
||
|
"unicode/utf8"
|
||
|
|
||
|
@@ -678,7 +679,6 @@ func getPythonExecPath() string {
|
||
|
// getRstContent calls the Python script rst2html as an external helper
|
||
|
// to convert reStructuredText content to HTML.
|
||
|
func getRstContent(ctx *RenderingContext) []byte {
|
||
|
- python := getPythonExecPath()
|
||
|
path := getRstExecPath()
|
||
|
|
||
|
if path == "" {
|
||
|
@@ -688,8 +688,19 @@ func getRstContent(ctx *RenderingContext) []byte {
|
||
|
|
||
|
}
|
||
|
jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
|
||
|
- args := []string{path, "--leave-comments", "--initial-header-level=2"}
|
||
|
- result := externallyRenderContent(ctx, python, args)
|
||
|
+ var result []byte
|
||
|
+ // certain *nix based OSs wrap executables in scripted launchers
|
||
|
+ // invoking binaries on these OSs via python interpreter causes SyntaxError
|
||
|
+ // invoke directly so that shebangs work as expected
|
||
|
+ // handle Windows manually because it doesn't do shebangs
|
||
|
+ if runtime.GOOS == "windows" {
|
||
|
+ python := getPythonExecPath()
|
||
|
+ args := []string{path, "--leave-comments", "--initial-header-level=2"}
|
||
|
+ result = externallyRenderContent(ctx, python, args)
|
||
|
+ } else {
|
||
|
+ args := []string{"--leave-comments", "--initial-header-level=2"}
|
||
|
+ result = externallyRenderContent(ctx, path, args)
|
||
|
+ }
|
||
|
// TODO(bep) check if rst2html has a body only option.
|
||
|
bodyStart := bytes.Index(result, []byte("<body>\n"))
|
||
|
if bodyStart < 0 {
|