|
1 | 1 | using System.Diagnostics; |
2 | 2 | using System.Reflection; |
3 | | -using System.Text; |
4 | 3 |
|
5 | 4 | using AIStudio.Tools.Metadata; |
6 | 5 | using AIStudio.Tools.Services; |
@@ -74,36 +73,49 @@ public PandocProcessBuilder UseStandaloneMode() |
74 | 73 |
|
75 | 74 | public async Task<PandocPreparedProcess> BuildAsync(RustService rustService) |
76 | 75 | { |
77 | | - var sbArguments = new StringBuilder(); |
78 | | - |
79 | | - if (this.useStandaloneMode) |
80 | | - sbArguments.Append(" --standalone "); |
81 | | - |
82 | | - if(!string.IsNullOrWhiteSpace(this.providedInputFile)) |
83 | | - sbArguments.Append(this.providedInputFile); |
84 | | - |
85 | | - if(!string.IsNullOrWhiteSpace(this.providedInputFormat)) |
86 | | - sbArguments.Append($" -f {this.providedInputFormat}"); |
87 | | - |
88 | | - if(!string.IsNullOrWhiteSpace(this.providedOutputFormat)) |
89 | | - sbArguments.Append($" -t {this.providedOutputFormat}"); |
90 | | - |
91 | | - foreach (var additionalArgument in this.additionalArguments) |
92 | | - sbArguments.Append($" {additionalArgument}"); |
93 | | - |
94 | | - if(!string.IsNullOrWhiteSpace(this.providedOutputFile)) |
95 | | - sbArguments.Append($" -o {this.providedOutputFile}"); |
96 | | - |
97 | 76 | var pandocExecutable = await PandocExecutablePath(rustService); |
98 | | - return new (new ProcessStartInfo |
| 77 | + var startInfo = new ProcessStartInfo |
99 | 78 | { |
100 | 79 | FileName = pandocExecutable.Executable, |
101 | | - Arguments = sbArguments.ToString(), |
102 | 80 | RedirectStandardOutput = true, |
103 | 81 | RedirectStandardError = true, |
104 | 82 | UseShellExecute = false, |
105 | 83 | CreateNoWindow = true |
106 | | - }, pandocExecutable.IsLocalInstallation); |
| 84 | + }; |
| 85 | + |
| 86 | + // Use argument tokens instead of a single command string so paths with spaces |
| 87 | + // or Unicode characters are passed to Pandoc unchanged on all platforms. |
| 88 | + if (this.useStandaloneMode) |
| 89 | + startInfo.ArgumentList.Add("--standalone"); |
| 90 | + |
| 91 | + if (!string.IsNullOrWhiteSpace(this.providedInputFile)) |
| 92 | + startInfo.ArgumentList.Add(this.providedInputFile); |
| 93 | + |
| 94 | + if (!string.IsNullOrWhiteSpace(this.providedInputFormat)) |
| 95 | + { |
| 96 | + startInfo.ArgumentList.Add("-f"); |
| 97 | + startInfo.ArgumentList.Add(this.providedInputFormat); |
| 98 | + } |
| 99 | + |
| 100 | + if (!string.IsNullOrWhiteSpace(this.providedOutputFormat)) |
| 101 | + { |
| 102 | + startInfo.ArgumentList.Add("-t"); |
| 103 | + startInfo.ArgumentList.Add(this.providedOutputFormat); |
| 104 | + } |
| 105 | + |
| 106 | + foreach (var additionalArgument in this.additionalArguments) |
| 107 | + { |
| 108 | + if (!string.IsNullOrWhiteSpace(additionalArgument)) |
| 109 | + startInfo.ArgumentList.Add(additionalArgument); |
| 110 | + } |
| 111 | + |
| 112 | + if (!string.IsNullOrWhiteSpace(this.providedOutputFile)) |
| 113 | + { |
| 114 | + startInfo.ArgumentList.Add("-o"); |
| 115 | + startInfo.ArgumentList.Add(this.providedOutputFile); |
| 116 | + } |
| 117 | + |
| 118 | + return new(startInfo, pandocExecutable.IsLocalInstallation); |
107 | 119 | } |
108 | 120 |
|
109 | 121 | /// <summary> |
|
0 commit comments