Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions MarkdownParse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//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;
Expand All @@ -13,11 +11,26 @@ public static ArrayList<String> getLinks(String markdown) {
int currentIndex = 0;
while(currentIndex < markdown.length()) {
int openBracket = markdown.indexOf("[", currentIndex);
int closeBracket = markdown.indexOf("]", openBracket);
int openParen = markdown.indexOf("(", closeBracket);
int closeParen = markdown.indexOf(")", openParen);
if(openBracket==-1){
break;
}
if(markdown.substring(currentIndex,openBracket).contains("!")){
int closeBracket = markdown.indexOf("]",openBracket);
int openParen = markdown.indexOf("(",closeBracket);
int closeParen = markdown.indexOf(")",openBracket);
currentIndex = closeParen + 1;
continue;
}
int closeBracket = markdown.indexOf("]",openBracket);
int openParen = markdown.indexOf("(",closeBracket);
if(openParen==-1){
break;
}
int closeParen = markdown.indexOf(")",openBracket);

toReturn.add(markdown.substring(openParen + 1, closeParen));
currentIndex = closeParen + 1;

}

return toReturn;
Expand All @@ -29,5 +42,6 @@ public static void main(String[] args) throws IOException {
String content = Files.readString(fileName);
ArrayList<String> links = getLinks(content);
System.out.println(links);

}
}
}
10 changes: 10 additions & 0 deletions MarkdownParseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import static org.junit.Assert.*;
import org.junit.*;
public class MarkdownParseTest {

@Test
public void addition() {
assertEquals(2, 1 + 1);
}

}
2 changes: 1 addition & 1 deletion test-file.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Title

[link1](https://something.com)
[link2](some-thing.html)
![image](some-thing.html)
6 changes: 6 additions & 0 deletions test-file2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Title

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

some paragraph text after the links
5 changes: 5 additions & 0 deletions test-file3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# title

[]

more text here
3 changes: 3 additions & 0 deletions test-file4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# title

[]link goes here!
7 changes: 7 additions & 0 deletions test-file5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# title

[stuff]

paragraph

(page.com)
3 changes: 3 additions & 0 deletions test-file6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# title

![link](page.com)
1 change: 1 addition & 0 deletions test-file7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
)[
2 changes: 2 additions & 0 deletions test-file8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[](a link on the first line)
[
3 changes: 3 additions & 0 deletions test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# test
[link](question(ddada).com)
![image](questionddd.com)