diff --git a/src/main/java/dev/jbang/source/sources/MarkdownSource.java b/src/main/java/dev/jbang/source/sources/MarkdownSource.java index 8baa33fc9..47b48db2d 100644 --- a/src/main/java/dev/jbang/source/sources/MarkdownSource.java +++ b/src/main/java/dev/jbang/source/sources/MarkdownSource.java @@ -52,7 +52,7 @@ public String transformMarkdown(String source) { List output = new ArrayList<>(); String state = "root"; boolean prevLineIsEmpty = true; - for (String line : source.split("\n")) { + for (String line : source.split("\\R")) { switch (state) { case "root": if (match(fourspacesOrTab, line) && prevLineIsEmpty) { diff --git a/src/test/java/dev/jbang/cli/TestRun.java b/src/test/java/dev/jbang/cli/TestRun.java index 89df14043..3ccc7f99f 100644 --- a/src/test/java/dev/jbang/cli/TestRun.java +++ b/src/test/java/dev/jbang/cli/TestRun.java @@ -238,6 +238,26 @@ void testMarkdown() throws IOException { assertThat(result, matchesPattern("^.*jshell(.exe)?.+--class-path=.*figlet.*? --startup.*$")); } + @Test + void testMarkdownWindows() throws IOException { + Path readmeFileOrg = examplesTestFolder.resolve("readme.md"); + String readmeText = Util.readString(readmeFileOrg); + + Path readmeFileWin = jbangTempDir.resolve("readme.md"); + Files.write(readmeFileWin, readmeText.replace("\n", "\r\n").getBytes()); + + String arg = readmeFileWin.toAbsolutePath().toString(); + CommandLine.ParseResult pr = JBang.getCommandLine().parseArgs("run", arg); + Run run = (Run) pr.subcommand().commandSpec().userObject(); + + ProjectBuilder pb = run.createProjectBuilderForRun(); + Project prj = pb.build(arg); + + String result = run.updateGeneratorForRun(CmdGenerator.builder(prj)).build().generate(); + + assertThat(result, matchesPattern("^.*jshell(.exe)?.+--class-path=.*figlet.*? --startup.*$")); + } + @Test void testRemoteMarkdown() throws IOException {