Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ea1470a
test for [ ]
AngeliaZddl Apr 14, 2022
6791d86
Update test1.md
AngeliaZddl Apr 14, 2022
8aa8447
Update test1.md
AngeliaZddl Apr 14, 2022
7911e18
Merge branch 'main' of https://github.com/AngeliaZddl/markdown-parser
AngeliaZddl Apr 14, 2022
c6c3155
Update test-file.md
AngeliaZddl Apr 14, 2022
47ec14f
add pic
AngeliaZddl Apr 21, 2022
121e888
start
AngeliaZddl Apr 24, 2022
54f295c
more tests
AngeliaZddl Apr 24, 2022
a5f205b
Set theme jekyll-theme-leap-day
AngeliaZddl Apr 24, 2022
bafc6dc
Set theme jekyll-theme-leap-day
AngeliaZddl Apr 24, 2022
bab8959
update
AngeliaZddl Apr 25, 2022
ea562b6
Merge branch 'main' of https://github.com/AngeliaZddl/markdown-parser
AngeliaZddl Apr 25, 2022
27f7db8
Update index.md
AngeliaZddl Apr 25, 2022
721c49d
Update index.md
AngeliaZddl Apr 25, 2022
854e167
update
AngeliaZddl Apr 25, 2022
d2ac0ee
testImage
AngeliaZddl Apr 25, 2022
46dcee3
testParen
AngeliaZddl Apr 25, 2022
0be8def
testBracket
AngeliaZddl Apr 25, 2022
01f7629
final
AngeliaZddl Apr 25, 2022
9c2716b
Update index.md
AngeliaZddl Apr 25, 2022
1d475ef
Update MarkdownParseTest.java
AngeliaZddl Apr 28, 2022
f246d90
Update MarkdownParseTest.java
AngeliaZddl Apr 28, 2022
bda4319
Delete index.md
AngeliaZddl Apr 28, 2022
f7e52ad
MarkdownParse from ieng6
AngeliaZddl May 10, 2022
d503040
Update MarkdownParse.java
AngeliaZddl May 10, 2022
afd40c9
Update MarkdownParseTest.java
AngeliaZddl May 10, 2022
1b66341
Update MarkdownParse.java
AngeliaZddl May 10, 2022
a5657a0
Update MarkdownParseTest.java
AngeliaZddl May 10, 2022
c36c655
Create lib
AngeliaZddl May 10, 2022
837af53
Delete lib
AngeliaZddl May 10, 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
10 changes: 10 additions & 0 deletions MarkdownParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ public static ArrayList<String> getLinks(String markdown) {
int currentIndex = 0;
while(currentIndex < markdown.length()) {
int openBracket = markdown.indexOf("[", currentIndex);
if (markdown.substring(openBracket-1, openBracket+1).equals("![")) {
int closeParen = markdown.indexOf(")", openBracket);
currentIndex = closeParen + 1;
continue;
}
int closeBracket = markdown.indexOf("]", openBracket);
if (closeBracket < 0 ) break;
int openParen = markdown.indexOf("(", closeBracket);
int closeParen = markdown.indexOf(")", openParen);
if (openParen+1 == closeParen) {
currentIndex = closeParen + 1;
continue;
}
toReturn.add(markdown.substring(openParen + 1, closeParen));
currentIndex = closeParen + 1;
}
Expand Down
58 changes: 58 additions & 0 deletions MarkdownParseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;


import org.junit.*;

public class MarkdownParseTest {

@Test
public void addition() {
// “assertEquals()” has two arguments. Will pass if the first arguement
// is equal to the second
assertEquals(2, 1 + 1);
}

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

@Test
public void testImage() throws IOException {
ArrayList<String> exp = new ArrayList<String>();
Path file = Path.of("testImage.md");
String content = Files.readString(file);
ArrayList<String> act = MarkdownParse.getLinks(content);
assertEquals(exp, act);
}

@Test
public void testParen() throws IOException {
List<String> exp = List.of("https://angeliazddl.github.io/markdown-parser/");
Path file = Path.of("testParen.md");
String content = Files.readString(file);
ArrayList<String> act = MarkdownParse.getLinks(content);
assertEquals(exp, act);
}

@Test
public void testBracket() throws IOException {
List<String> exp = List.of("https://angeliazddl.github.io/markdown-parser/");
Path file = Path.of("testBracket.md");
String content = Files.readString(file);
ArrayList<String> act = MarkdownParse.getLinks(content);
assertEquals(exp, act);
}

}
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-leap-day
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)
[link2](some-thing.html)
3 changes: 3 additions & 0 deletions testBracket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CSE15L

[back](https://angeliazddl.github.io/markdown-parser/) [
3 changes: 3 additions & 0 deletions testImage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CSE15L

![Sunset](sunset.jpg)
5 changes: 5 additions & 0 deletions testParen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CSE15L

[link]()

[back](https://angeliazddl.github.io/markdown-parser/)