Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
89783dd
Update test-file.md
thELanee Apr 15, 2022
5cf86bb
Update test-file.md
thELanee Apr 15, 2022
a91e397
Create test-file2.md
thELanee Apr 15, 2022
eb00e94
Added new files
thELanee Apr 22, 2022
330a380
Merge branch 'main' of https://github.com/thELanee/markdown-parser
thELanee Apr 22, 2022
b246b71
Update .gitignore
thELanee Apr 22, 2022
fee3e80
Added jar files
thELanee Apr 22, 2022
aec8318
Added new test files
thELanee Apr 22, 2022
4a659f6
changes
thELanee Apr 22, 2022
13f72a3
Update test-file3.md
thELanee Apr 23, 2022
85be896
changed test3 and deleted some comments
thELanee Apr 29, 2022
0f84636
Merge branch 'main' of https://github.com/thELanee/markdown-parser
thELanee Apr 29, 2022
16084e0
Update MarkdownParseTest.java
thELanee Apr 29, 2022
60545ee
Create workflows
thELanee Apr 29, 2022
fe2eb4e
Delete actions.github directory
thELanee Apr 29, 2022
1f44b8e
Create github-actions-demo.yml
thELanee Apr 29, 2022
e90db5f
Delete actions.github/workflows directory
thELanee Apr 29, 2022
c831431
Create github-actions-demo.yml
thELanee Apr 29, 2022
8b6635f
Update github-actions-demo.yml
thELanee Apr 29, 2022
16d55af
Delete github-actions-demo.yml
thELanee Apr 29, 2022
0137b94
Create github-actions-demo.yml
thELanee Apr 29, 2022
a1f5ace
Merge pull request #2 from thELanee/thELanee-actions
thELanee Apr 29, 2022
2bd284f
Update github-actions-demo.yml
thELanee Apr 29, 2022
6bc3158
Update github-actions-demo.yml
thELanee Apr 29, 2022
bdc4514
Update github-actions-demo.yml
thELanee Apr 29, 2022
e5772c1
Update github-actions-demo.yml
thELanee Apr 29, 2022
34cd82b
Update github-actions-demo.yml
thELanee Apr 29, 2022
ee47be1
Update github-actions-demo.yml
thELanee Apr 29, 2022
9566eea
Update github-actions-demo.yml
thELanee Apr 29, 2022
9dd43f6
Update github-actions-demo.yml
thELanee Apr 29, 2022
506d644
Update MarkdownParseTest.java
thELanee Apr 29, 2022
88388a0
Merge branch 'main' of https://github.com/thELanee/markdown-parser
thELanee Apr 29, 2022
3e395b1
Update github-actions-demo.yml
thELanee Apr 29, 2022
061ef1d
Update github-actions-demo.yml
thELanee Apr 29, 2022
4b1895b
Update github-actions-demo.yml
thELanee Apr 29, 2022
67bb7da
Update github-actions-demo.yml
thELanee Apr 29, 2022
b5d490b
Push a failing test
thELanee Apr 29, 2022
b312210
Merge branch 'main' of https://github.com/thELanee/markdown-parser
thELanee Apr 29, 2022
8df1678
Updates failing test
thELanee Apr 29, 2022
adb60e9
Update MarkdownParseTest.java
thELanee Apr 29, 2022
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
17 changes: 17 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: GitHub Actions Demo
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run JUnit Tests
run: |
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

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
Expand Down
31 changes: 30 additions & 1 deletion MarkdownParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,42 @@ public static ArrayList<String> getLinks(String markdown) {
// find the next [, then find the ], then find the (, then read link upto next )
int currentIndex = 0;
while(currentIndex < markdown.length()) {
int openBracket = markdown.indexOf("[", currentIndex);
int openBracket = markdown.indexOf("[", currentIndex);
if (openBracket == -1) {
break;
}

//Checks if there is an "!" that denotes an image link before the open bracket and ends the loop if there is.

if (openBracket != 0) {
if (markdown.substring(openBracket - 1, openBracket).equals("!")) {
currentIndex = openBracket + 1;
continue;
}
}

int closeBracket = markdown.indexOf("]", openBracket);
if (closeBracket == -1) {
break;
}
int openParen = markdown.indexOf("(", closeBracket);

if (openParen == -1 || openParen != closeBracket + 1) {
break;
}

int closeParen = markdown.indexOf(")", openParen);


if (closeParen == -1) {
break;
}

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

currentIndex = closeParen + 1;
}
//41, 67

return toReturn;
}
Expand Down
108 changes: 108 additions & 0 deletions MarkdownParseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import java.util.ArrayList;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Files;
import static org.junit.Assert.*;
import org.junit.*;
import java.util.List;

public class MarkdownParseTest {
@Test
public void addition() {
assertEquals(2, 1 + 1);
}
@Test
public void testFile() throws IOException {
Path fileName = Path.of("./test-file.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of("https://something.com", "some-thing.html"), links);
}

@Test
public void testFile2() throws IOException {
Path fileName = Path.of("./test-file2.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of("https://something.com", "some-thing.html"), links);
}

@Test
public void testFile3() throws IOException {
Path fileName = Path.of("./test-file3.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of("https://something.com", "some-thing.html"), links);
}

@Test
public void testFile4() throws IOException {
Path fileName = Path.of("./test-file4.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of("https://something.com", "some-thing.html"), links);
}

@Test
public void testFiles2() throws IOException {
Path fileName = Path.of("./testfiles/test-file2.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of("https://something.com", "some-page.html"), links);
}

@Test
public void testFiles3() throws IOException {
Path fileName = Path.of("./testfiles/test-file3.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of(), links);
}

@Test
public void testFiles4() throws IOException {
Path fileName = Path.of("./testfiles/test-file4.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of(), links);
}

@Test
public void testFiles5() throws IOException {
Path fileName = Path.of("./testfiles/test-file5.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of(), links);
}

@Test
public void testFiles6() throws IOException {
Path fileName = Path.of("./testfiles/test-file6.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of(), links);
}

@Test
public void testFiles7() throws IOException {
Path fileName = Path.of("./testfiles/test-file7.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of(), links);
}

@Test
public void testFiles8() throws IOException {
Path fileName = Path.of("./testfiles/test-file8.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of("a link on the first line"), links);
}
@Test
public void fileNotHere() throws IOException {
Path fileName = Path.of("./testfiles/test-file9.md");
String content = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(content);
assertEquals(List.of(), links);
}
}
Binary file added lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added lib/junit-4.13.2.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions test-file2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Title

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

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

[link1](https://something.com)
[link2](some-thing.html)
[

](onomotopoeia
6 changes: 6 additions & 0 deletions testfiles/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 testfiles/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 testfiles/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 testfiles/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 testfiles/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 testfiles/test-file7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
)[
2 changes: 2 additions & 0 deletions testfiles/test-file8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[](a link on the first line)
[
Empty file added testfiles/test-file9.md
Empty file.