Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7dbc154
Identifies Image source links as url links
Miyuki-L Apr 14, 2022
54e14a9
Fixed image link identification bug
Miyuki-L Apr 14, 2022
cb997e0
Fixed not identifying links when there are images
Miyuki-L Apr 14, 2022
fb2e6e7
Fixed bug when at least one of []() isn't present
Miyuki-L Apr 14, 2022
e9cd131
Removed New line at EOF that causes infinite loop
Miyuki-L Apr 14, 2022
d7fbaee
Edited gitignore for .jar and added JUnit Jar files
Miyuki-L Apr 21, 2022
324bfb7
Created TestFile and initial Sample test
Miyuki-L Apr 21, 2022
d5f1300
Wrote unit Test on test-file.md
Miyuki-L Apr 21, 2022
427a832
Wrote tests for the other test files
Miyuki-L Apr 21, 2022
c6857ee
Added additional test-files that were given
Miyuki-L Apr 21, 2022
d235246
Refactored the code to utilize readFile helper
Miyuki-L Apr 21, 2022
56cb00b
fixed empty [] (links) error
Miyuki-L Apr 21, 2022
b198fe9
Update image and link order
Miyuki-L Apr 23, 2022
324f8d1
Added code for and test for empty paren case
Miyuki-L Apr 28, 2022
de2a78b
Create Junit Command
Miyuki-L Apr 28, 2022
9d0e20d
Create main.yml
DanielMilesGH Apr 28, 2022
5c3e43d
Removed Local Computer Specific path
Miyuki-L Apr 28, 2022
6db9a2b
Added support for "\"
DanielMilesGH Apr 28, 2022
4a3c319
Create test-file9.md
DanielMilesGH Apr 28, 2022
07aeba5
Update MarkdownParseTest.java
DanielMilesGH Apr 28, 2022
8aa10c0
added }
DanielMilesGH Apr 28, 2022
08b171d
Removed check for escape so that it fails Junit
Miyuki-L Apr 28, 2022
b5708af
Added missing ) that didn't make the file compile
Miyuki-L Apr 28, 2022
f409669
Reverting back to "\" support.
DanielMilesGH Apr 28, 2022
fced103
Update MarkdownParse.java
AngeliaZddl Apr 28, 2022
e8720a8
Update to Makefile
stevex626 May 5, 2022
84e4bfa
Update main.yml
stevex626 May 5, 2022
c5001a6
Create mdparse
Miyuki-L May 5, 2022
76b80a3
add file to test push
May 16, 2022
a9a4297
Updated MakeFile
Miyuki-L May 19, 2022
eca7107
added CommonMark and CommonMark example file
Miyuki-L Jun 2, 2022
2d8ab92
Merge branch 'main' of https://github.com/Miyuki-L/markdown-parser
Miyuki-L Jun 2, 2022
177fdc7
Added CommonMark's WordCountVisitor example
Miyuki-L Jun 2, 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
29 changes: 29 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This is a basic workflow to help you get started with Actions

name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
make MarkdownParseTest.class
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
7 changes: 7 additions & 0 deletions Junit Command
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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


linux and mac
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
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CLASSPATH = lib/*:.
MarkdownParse.class: MarkdownParse.java
javac MarkdownParse.java
MarkdownParseTest.class: MarkdownParseTest.java MarkdownParse.class
javac -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar MarkdownParseTest.java
Test: MarkdownParseTest.class MarkdownParse.class
java -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar org.junit.runner.JUnitCore MarkdownParseTest

TryCommonMark.class: TryCommonMark.java
javac -g -cp $(CLASSPATH) TryCommonMark.java

TestTryCommonMark : TryCommonMark.class
java -cp lib/*:. TryCommonMark
32 changes: 30 additions & 2 deletions MarkdownParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,37 @@ public static ArrayList<String> getLinks(String markdown) {
int closeBracket = markdown.indexOf("]", openBracket);
int openParen = markdown.indexOf("(", closeBracket);
int closeParen = markdown.indexOf(")", openParen);
toReturn.add(markdown.substring(openParen + 1, closeParen));

int openBrackPrevIndex = openBracket-1;
// System.out.println(markdown.substring(openParen + 1, closeParen));
// check if escape character
if (openBracket == -1 || closeBracket ==-1 || openParen == -1 || closeParen == -1){
break;
}

if (openBrackPrevIndex >=0 && (
markdown.substring(openBrackPrevIndex, openBracket).equals("!") || markdown.substring(openBrackPrevIndex, openBracket).equals("\\"))) {
// System.out.println("image");
// Math.max(openBracket,closeBracket, openParen,closePare/n);
}
else if (openBracket + 1 == closeBracket) {}
else if (openParen + 1 == closeParen) {
currentIndex = closeParen + 1;
continue;}
else if (openBracket == 0) {
System.out.println("zero");
toReturn.add(markdown.substring(openParen + 1, closeParen));
}
else if (closeBracket + 1 == openParen) {
// System.out.println("]( next to eachother");
toReturn.add(markdown.substring(openParen + 1, closeParen));
}

// Cases gets triggered falsly. ONe is that it might trigger another case while it isn't a link. Faulty
currentIndex = closeParen + 1;
// System.out.println(currentIndex);
}

System.out.println(toReturn.toString());
return toReturn;
}

Expand All @@ -30,4 +57,5 @@ public static void main(String[] args) throws IOException {
ArrayList<String> links = getLinks(content);
System.out.println(links);
}
//Testing purpose 11111111
}
125 changes: 125 additions & 0 deletions MarkdownParseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import static org.junit.Assert.*;
import org.junit.*;

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

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

public String readFile(String file) throws IOException {
String fullPath = file;
Path fileName = Path.of(fullPath);
String content = Files.readString(fileName);
return content;
}

@Test
public void testProvidedTestFile() throws IOException {
String content = readFile("test-file.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {"https://something.com", "some-thing.html"};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testTest2File() throws IOException {
String content = readFile("test2.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[0];
assertArrayEquals(expected, links.toArray());
}

@Test
public void testTestNoLink() throws IOException {
String content = readFile("testNoLink.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[0];
assertArrayEquals(expected, links.toArray());
}

@Test
public void testTestImageAndLink() throws IOException {
String content = readFile("testImageAndLink.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {"shouldbeidentified.com"};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testProvidedTestFile2() throws IOException {
String content = readFile("test-file2.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {"https://something.com", "some-page.html"};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testProvidedTestFile3() throws IOException {
String content = readFile("test-file3.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testProvidedTestFile4() throws IOException {
String content = readFile("test-file4.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testProvidedTestFile5() throws IOException {
String content = readFile("test-file5.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testProvidedTestFile6() throws IOException {
String content = readFile("test-file6.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testProvidedTestFile7() throws IOException {
String content = readFile("test-file7.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testProvidedTestFile8() throws IOException {
String content = readFile("test-file8.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {};
assertArrayEquals(expected, links.toArray());
}

@Test
public void testProvidedTestEmptyParen() throws IOException {
String content = readFile("testNoLinkInParen.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {};
assertArrayEquals(expected, links.toArray());
}
@Test
public void testProvidedTest9() throws IOException {
String content = readFile("test-file9.md");
ArrayList<String> links = MarkdownParse.getLinks(content);
String[] expected = new String[] {};
assertArrayEquals(expected, links.toArray());
}
//Helloooo
}
38 changes: 38 additions & 0 deletions TryCommonMark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import org.commonmark.node.*;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;

class TryCommonMark {
public static void main(String[] args) {
Parser parser = Parser.builder().build();
Node document = parser.parse("This is *Sparta*");
HtmlRenderer renderer = HtmlRenderer.builder().build();
String content = renderer.render(document); // "<p>This is <em>Sparta</em></p>\n"
// System.out.println(content);

// # this part actually does the computation
Node node = parser.parse("Example\n=======\n\nSome more text");
WordCountVisitor visitor = new WordCountVisitor();
node.accept(visitor);
// visitor.wordCount; // 4
System.out.println(visitor.wordCount);
}


}

// # this class can be defined anywhere in the file
class WordCountVisitor extends AbstractVisitor {
int wordCount = 0;

@Override
public void visit(Text text) {
// This is called for all Text nodes. Override other visit methods for other node types.

// Count words (this is just an example, don't actually do it this way for various reasons).
wordCount += text.getLiteral().split("\\W+").length;

// Descend into children (could be omitted in this case because Text nodes don't have children).
visitChildren(text);
}
}
Binary file added lib/commonmark-0.19.0.jar
Binary file not shown.
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.
1 change: 1 addition & 0 deletions mdparse
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java -cp lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar:. MarkdownParse $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)
[link2](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)
[
1 change: 1 addition & 0 deletions test-file9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\[an-escaped-link](test)
1 change: 1 addition & 0 deletions test2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hi ![Google](https://www.google.com/logos/doodles/2021/doodle-champion-island-games-begin-6753651837108462.2-2xa.gif)
3 changes: 3 additions & 0 deletions testImageAndLink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
![setting Icon]( https://www.google.com/logos/doodles/2017/celebrating-50-years-of-kids-coding-5745168905928704.4-lawcta.gif)

[This is an URL Link](shouldbeidentified.com)
1 change: 1 addition & 0 deletions testNoLink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(pretend)[link
1 change: 1 addition & 0 deletions testNoLinkInParen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[link empty]()