Skip to content
Open

pull #17

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
36 changes: 36 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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 Run

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.mtj.tmp/

# Package Files #
*.jar

*.war
*.nar
*.ear
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"makefile.extensionOutputFolder": "./.vscode"
}
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CLASSPATH = lib\*;.

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

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

Run: MarkdownParseTest.class
java -cp ".;lib/junit-4.13.2.jar;lib/hamcrest-core-1.3.jar" org.junit.runner.JUnitCore MarkdownParseTest
26 changes: 25 additions & 1 deletion MarkdownParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ public static ArrayList<String> getLinks(String markdown) {
int closeBracket = markdown.indexOf("]", openBracket);
int openParen = markdown.indexOf("(", closeBracket);
int closeParen = markdown.indexOf(")", openParen);
int exclamation = markdown.indexOf("!", currentIndex);
int backtick = markdown.indexOf("`", currentIndex);
int innerParen = markdown.indexOf("(", openParen+1);
if (innerParen > openParen && innerParen < closeParen){
closeParen++;
currentIndex = closeParen + 1;
continue;
}
if (exclamation >= currentIndex && exclamation == openBracket - 1){
currentIndex = closeParen + 1;
continue;
}
if (backtick >= currentIndex && backtick == openBracket - 1){
currentIndex = closeParen + 1;
continue;
}
if (openBracket == -1 || closeBracket == -1 ||
openParen == -1 || closeParen == -1){
break;
}
if (markdown.charAt(openParen-1) != markdown.charAt(closeBracket)){
currentIndex = closeParen + 1;
continue;
}
toReturn.add(markdown.substring(openParen + 1, closeParen));
currentIndex = closeParen + 1;
}
Expand All @@ -24,7 +48,7 @@ public static ArrayList<String> getLinks(String markdown) {
}


public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException{
Path fileName = Path.of(args[0]);
String content = Files.readString(fileName);
ArrayList<String> links = getLinks(content);
Expand Down
118 changes: 118 additions & 0 deletions MarkdownParseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import static org.junit.Assert.*;

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

import org.junit.*;
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);
assertEquals(List.of("https://something.com", "some-thing.html"),MarkdownParse.getLinks(content));
}

@Test
public void break1() throws IOException{
Path fileName = Path.of("breaking-test1.md");
String content = Files.readString(fileName);
assertEquals(List.of(),MarkdownParse.getLinks(content));
}

@Test
public void break3() throws IOException{
Path fileName = Path.of("breaking-test2.md");
String content = Files.readString(fileName);
assertEquals(List.of("https://something.com", "some-thing.html"),MarkdownParse.getLinks(content));
}

@Test
public void break2() throws IOException{
Path fileName = Path.of("breaking-test3.md");
String content = Files.readString(fileName);
assertEquals(List.of("https://something.com"),MarkdownParse.getLinks(content));
}

@Test
public void testLinks() throws IOException{
Path fileName = Path.of("test-file.md");
String content = Files.readString(fileName);
assertEquals(List.of("https://something.com", "some-thing.html"), MarkdownParse.getLinks(content));
}
@Test
public void testLink2() throws IOException{
Path fileName = Path.of("test-file2.md");
String content = Files.readString(fileName);
assertEquals(List.of("https://something.com", "some-page.html"), MarkdownParse.getLinks(content));
}
@Test
public void testLink3() throws IOException{
Path fileName = Path.of("test-file3.md");
String content = Files.readString(fileName);
assertEquals(List.of(), MarkdownParse.getLinks(content));
}
@Test
public void testLink4() throws IOException{
Path fileName = Path.of("test-file4.md");
String content = Files.readString(fileName);
assertEquals(List.of(), MarkdownParse.getLinks(content));
}
@Test
public void testLink5() throws IOException{
Path fileName = Path.of("test-file5.md");
String content = Files.readString(fileName);
assertEquals(List.of(), MarkdownParse.getLinks(content));
}
@Test
public void testLink6() throws IOException{
Path fileName = Path.of("test-file6.md");
String content = Files.readString(fileName);
assertEquals(List.of(), MarkdownParse.getLinks(content));
}
@Test
public void testLink7() throws IOException{
Path fileName = Path.of("test-file7.md");
String content = Files.readString(fileName);
assertEquals(List.of(), MarkdownParse.getLinks(content));
}
@Test
public void testLink8() throws IOException{
Path fileName = Path.of("test-file8.md");
String content = Files.readString(fileName);
assertEquals(List.of("a link on the first line"), MarkdownParse.getLinks(content));
}
@Test
public void testLink9() throws IOException{
Path fileName = Path.of("test-file9.md");
String content = Files.readString(fileName);
assertEquals(List.of(), MarkdownParse.getLinks(content));
}
@Test
public void testSnippet1() throws IOException{
Path fileName = Path.of("snippet1.md");
String content = Files.readString(fileName);
assertEquals(List.of("`google.com", "google.com", "ucsd.edu"), MarkdownParse.getLinks(content));
}
@Test
public void testSnippet2() throws IOException{
Path fileName = Path.of("snippet2.md");
String content = Files.readString(fileName);
assertEquals(List.of("a.com", "a.com(())", "example.com"), MarkdownParse.getLinks(content));
}
@Test
public void testSnippet3() throws IOException{
Path fileName = Path.of("snippet3.md");
String content = Files.readString(fileName);
assertEquals(List.of("https://www.twitter.com",
"https://sites.google.com/eng.ucsd.edu/cse-15l-spring-2022/schedule",
"https://cse.ucsd.edu/"), MarkdownParse.getLinks(content));
}
}
12 changes: 12 additions & 0 deletions TryCommonMark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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(); // "<p>This is <em>Sparta</em></p>\n"
System.out.println(renderer.render(document));
}
}
1 change: 1 addition & 0 deletions breaking-test1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Breaking test
5 changes: 5 additions & 0 deletions breaking-test2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Breaking test 2

[link1](https://something.com)
[link2](some-thing.html)
![image](https://www.snopes.com/tachyon/2018/07/poop_emoji.jpg)
4 changes: 4 additions & 0 deletions breaking-test3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Breaking test 3

[link1](https://something.com)
][)(
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.
7 changes: 7 additions & 0 deletions snippet1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
`[a link`](url.com)

[another link](`google.com)`

[`cod[e`](google.com)

[`code]`](ucsd.edu)
5 changes: 5 additions & 0 deletions snippet2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[a [nested link](a.com)](b.com)

[a nested parenthesized url](a.com(()))

[some escaped \[ brackets \]](example.com)
24 changes: 24 additions & 0 deletions snippet3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[this title text is really long and takes up more than
one line

and has some line breaks](
https://www.twitter.com
)

[this title text is really long and takes up more than
one line](
https://sites.google.com/eng.ucsd.edu/cse-15l-spring-2022/schedule
)


[this link doesn't have a closing parenthesis](github.com

And there's still some more text after that.

[this link doesn't have a closing parenthesis for a while](https://cse.ucsd.edu/



)

And then there's more text
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 @@
[](())