Skip to content

Commit

Permalink
fix: Markdown files now handled properly on Windows (#1856)
Browse files Browse the repository at this point in the history
Fixes #1855
  • Loading branch information
quintesse authored Oct 31, 2024
1 parent 2aa4b0d commit e0d4d8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/dev/jbang/source/sources/MarkdownSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String transformMarkdown(String source) {
List<String> 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) {
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/dev/jbang/cli/TestRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit e0d4d8e

Please sign in to comment.