Skip to content

Commit

Permalink
added some commented stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Ripslash committed Jan 28, 2022
1 parent ff64fe2 commit b501efb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
Binary file modified MarkdownParse.class
Binary file not shown.
54 changes: 43 additions & 11 deletions MarkdownParse.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,64 @@
// // File reading code from https://howtodoinjava.com/java/io/java-read-file-to-string-examples/
// import java.io.IOException;
// import java.nio.file.Files;
// import java.nio.file.Path;
// import java.util.ArrayList;

// //javac -cp ".;lib\junit-4.13.2.jar;lib\hamcrest-core-1.3.jar" MarkdownParseTest.java
// //java -cp ".;lib/junit-4.13.2.jar;lib/hamcrest-core-1.3.jar" org.junit.runner.JUnitCore MarkdownParseTest

// public class MarkdownParse {
// public static ArrayList<String> getLinks(String markdown) {
// ArrayList<String> toReturn = new ArrayList<>();
// // find the next [, then find the ], then find the (, then take up to
// // the next )
// boolean shatter = true;
// int currentIndex = 0;
// while(currentIndex < markdown.length()) {
// int nextOpenBracket = markdown.indexOf("[", currentIndex);
// if(nextOpenBracket == -1) break;
// int nextCloseBracket = markdown.indexOf("]", nextOpenBracket);
// if(nextCloseBracket == -1) break;
// int openParen = markdown.indexOf("(", nextCloseBracket);
// if(openParen == -1) break;
// int closeParen = markdown.indexOf(")", openParen);
// if(closeParen == -1) break;
// //while(shatter == true) {}
// toReturn.add(markdown.substring(openParen + 1, closeParen));
// currentIndex = closeParen + 1;
// System.out.println(currentIndex);
// }
// return toReturn;
// }
// public static void main(String[] args) throws IOException {
// Path fileName = Path.of(args[0]);
// String contents = Files.readString(fileName);
// ArrayList<String> links = getLinks(contents);
// System.out.println(links);
// }
// }



// File reading code from https://howtodoinjava.com/java/io/java-read-file-to-string-examples/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;

//javac -cp ".;lib\junit-4.13.2.jar;lib\hamcrest-core-1.3.jar" MarkdownParseTest.java
//java -cp ".;lib/junit-4.13.2.jar;lib/hamcrest-core-1.3.jar" org.junit.runner.JUnitCore MarkdownParseTest

public class MarkdownParse {
public static ArrayList<String> getLinks(String markdown) {
ArrayList<String> toReturn = new ArrayList<>();
// find the next [, then find the ], then find the (, then take up to
// the next )
boolean shatter = true;
int currentIndex = 0;
while(currentIndex < markdown.length()) {
int nextOpenBracket = markdown.indexOf("[", currentIndex);
if(nextOpenBracket == -1) break;
int nextCloseBracket = markdown.indexOf("]", nextOpenBracket);
if(nextCloseBracket == -1) break;
int openParen = markdown.indexOf("(", nextCloseBracket);
if(openParen == -1) break;
int closeParen = markdown.indexOf(")", openParen);
if(closeParen == -1) break;
//while(shatter == true) {}
toReturn.add(markdown.substring(openParen + 1, closeParen));
currentIndex = closeParen + 1;
System.out.println(currentIndex);
}
return toReturn;
}
Expand All @@ -36,4 +68,4 @@ public static void main(String[] args) throws IOException {
ArrayList<String> links = getLinks(contents);
System.out.println(links);
}
}
}
1 change: 1 addition & 0 deletions test-file.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Title


[a link!](https://something.com)
[another link!](some-page.html)

0 comments on commit b501efb

Please sign in to comment.