Skip to content

Commit e1e0b12

Browse files
Add newline normalizing utility function
1 parent f0189cb commit e1e0b12

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocgenUtils.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public static String runCommand(String command, Path directory) {
4444
}
4545

4646
ProcessBuilder processBuilder = new ProcessBuilder(finalizedCommand)
47-
.redirectErrorStream(true)
48-
.directory(directory.toFile());
47+
.redirectErrorStream(true)
48+
.directory(directory.toFile());
4949

5050
try {
5151
Process process = processBuilder.start();
@@ -74,4 +74,13 @@ public static String runCommand(String command, Path directory) {
7474
throw new CodegenException(e);
7575
}
7676
}
77+
78+
/**
79+
* Replaces all newline characters in a string with the system line separator.
80+
* @param input The string to normalize
81+
* @return A string with system-appropriate newlines.
82+
*/
83+
public static String normalizeNewlines(String input) {
84+
return input.replaceAll("\r?\n", System.lineSeparator());
85+
}
7786
}

smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/integrations/SphinxIntegration.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package software.amazon.smithy.docgen.core.integrations;
77

88
import static java.lang.String.format;
9+
import static software.amazon.smithy.docgen.core.DocgenUtils.normalizeNewlines;
910
import static software.amazon.smithy.docgen.core.DocgenUtils.runCommand;
1011

1112
import java.util.List;
@@ -234,25 +235,27 @@ private void runSphinx(DocGenerationContext context) {
234235
// Finally, run sphinx itself.
235236
runCommand("./venv/bin/sphinx-build -M dirhtml content build", baseDir);
236237

237-
System.out.printf("""
238-
Successfully built HTML docs. They can be found in "%1$s".\
239-
%n%n\
238+
System.out.printf(normalizeNewlines("""
239+
Successfully built HTML docs. They can be found in "%1$s".
240+
240241
Other output formats can also be built. A python virtual environment \
241242
has been created at "%2$s" containing the build tools needed for \
242243
manually building the docs in other formats. See the virtual \
243244
environment docs for information on how to activate it: \
244-
https://docs.python.org/3/library/venv.html#how-venvs-work\
245-
%n%n\
245+
https://docs.python.org/3/library/venv.html#how-venvs-work
246+
246247
Once the environment is activated, run `make dirhtml` from "%3$s" to \
247248
to build the docs, substituting dirhtml for whatever format you wish \
248-
to build.\
249-
%n%n\
249+
to build.
250+
250251
To build the docs without activating the virtual environment, simply \
251252
run `./venv/bin/sphinx-build -M dirhtml content build` from "%3$s", \
252-
similarly substituting dirhtml for your desired format.\
253-
%n%n\
253+
similarly substituting dirhtml for your desired format.
254+
254255
See sphinx docs for other output formats you can choose: \
255-
https://www.sphinx-doc.org/en/master/usage/builders/index.html%n%n""",
256+
https://www.sphinx-doc.org/en/master/usage/builders/index.html
257+
258+
"""),
256259
baseDir.resolve("build/dirhtml"),
257260
baseDir.resolve("venv"),
258261
baseDir
@@ -265,18 +268,20 @@ private void runSphinx(DocGenerationContext context) {
265268

266269
private void logManualBuildInstructions(DocGenerationContext context) {
267270
// TODO: try to get this printed out in the projection section
268-
System.out.printf("""
271+
System.out.printf(normalizeNewlines("""
269272
To build the HTML docs manually, you need to first install the python \
270273
dependencies. These can be found in the `requirements.txt` file in \
271274
"%1$s". The easiest way to install these is by running `pip install \
272275
-r requirements.txt`. Depending on your environment, you may need to \
273276
instead install them from your system package manager, or another \
274-
source.\
275-
%n%n\
277+
source.
278+
276279
Once the dependencies are installed, run `make dirhtml` from \
277280
"%1$s". Other output formats can also be built. See sphinx docs for \
278281
other output formats: \
279-
https://www.sphinx-doc.org/en/master/usage/builders/index.html%n%n""",
282+
https://www.sphinx-doc.org/en/master/usage/builders/index.html
283+
284+
"""),
280285
context.fileManifest().getBaseDir()
281286
);
282287
}

0 commit comments

Comments
 (0)