@@ -10,6 +10,7 @@ import (
10
10
"io/ioutil"
11
11
"os"
12
12
"os/exec"
13
+ "runtime"
13
14
"strings"
14
15
15
16
"code.gitea.io/gitea/modules/log"
@@ -41,13 +42,24 @@ func (p *Parser) Extensions() []string {
41
42
return p .FileExtensions
42
43
}
43
44
45
+ func envMark (envName string ) string {
46
+ if runtime .GOOS == "windows" {
47
+ return "%" + envName + "%"
48
+ }
49
+ return "$" + envName
50
+ }
51
+
44
52
// Render renders the data of the document to HTML via the external tool.
45
53
func (p * Parser ) Render (rawBytes []byte , urlPrefix string , metas map [string ]string , isWiki bool ) []byte {
46
54
var (
47
- bs []byte
48
- buf = bytes .NewBuffer (bs )
49
- rd = bytes .NewReader (rawBytes )
50
- commands = strings .Fields (p .Command )
55
+ bs []byte
56
+ buf = bytes .NewBuffer (bs )
57
+ rd = bytes .NewReader (rawBytes )
58
+ urlRawPrefix = strings .Replace (urlPrefix , "/src/" , "/raw/" , 1 )
59
+
60
+ command = strings .NewReplacer (envMark ("GITEA_PREFIX_SRC" ), urlPrefix ,
61
+ envMark ("GITEA_PREFIX_RAW" ), urlRawPrefix ).Replace (p .Command )
62
+ commands = strings .Fields (command )
51
63
args = commands [1 :]
52
64
)
53
65
@@ -79,7 +91,7 @@ func (p *Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]stri
79
91
cmd .Env = append (
80
92
os .Environ (),
81
93
"GITEA_PREFIX_SRC=" + urlPrefix ,
82
- "GITEA_PREFIX_RAW=" + strings . Replace ( urlPrefix , "/src/" , "/raw/" , 1 ) ,
94
+ "GITEA_PREFIX_RAW=" + urlRawPrefix ,
83
95
)
84
96
if ! p .IsInputFile {
85
97
cmd .Stdin = rd
0 commit comments