-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
73 lines (48 loc) · 2.76 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.*;
public class Main {
final static String WHITESPACE_REGEX = "\\s";
final static String[] COMMAND_LIST = {"help", "jmd"};
final static String[] CSS_TEMPLATE_LIGHT = {"#f7f7fa", "#0e0f18", "#bfa5ca", "#bfa5ca", "#b280b4"};
final static String[] CSS_TEMPLATE_DARK = {"#060609", "#e9e9f2", "#bfa5ca", "#4f355a", "#7f4b81"};
final static Map<String, String> COMMAND_DESCRIPTIONS = new HashMap<>(Map.ofEntries(
Map.entry("help", "Provides a list of commands and what they do."),
Map.entry("jmd", "JMD (Java Markdown) is the starting command to convert Markdown into HTML."),
Map.entry("--darkmode", "--darkmode is a JMD flag to output HTML with a darker style of CSS instead of the default light style."),
Map.entry("Supported Markdown", "Headings, normal text, links, lists, quotes, italic text, bold text, italic & bold text.")
));
public static void main(String[] args) {
System.out.println("Welcome to JMD (Java Markdown).\nThis is a tool to convert MarkDown to a HTML file.");
System.out.println("Use the 'help' command otherwise have fun converting.");
Scanner scanner = new Scanner(System.in);
String userInput = scanner.nextLine();
String[] userInputTokens = userInput.split(WHITESPACE_REGEX);
String userCommand = userInputTokens[0].toLowerCase();
while(!Arrays.asList(COMMAND_LIST).contains(userCommand)) {
System.out.println("You did not enter a correct command.\nUse 'help' for a list of commands");
userInput = scanner.nextLine();
userInputTokens = userInput.split(WHITESPACE_REGEX);
userCommand = userInputTokens[0].toLowerCase();
}
scanner.close();
switch(userCommand) {
case "help":
COMMAND_DESCRIPTIONS.forEach((key, value) -> System.out.println(key + ": " + value));
break;
case "jmd":
String filePath = userInputTokens[1];
boolean darkmodeFlag = Arrays.asList(userInputTokens).contains("--darkmode");
JMD(filePath, darkmodeFlag);
break;
}
}
private static void JMD(String filePath, boolean darkmodeFlag) {
List<String> htmlElements = Files.ReadFile(filePath);
String css = HTMLElements.CSSTemplate();
if (!darkmodeFlag) {
css = String.format(css, CSS_TEMPLATE_LIGHT[0], CSS_TEMPLATE_LIGHT[1], CSS_TEMPLATE_LIGHT[2], CSS_TEMPLATE_LIGHT[3], CSS_TEMPLATE_LIGHT[4]);
} else {
css = String.format(css, CSS_TEMPLATE_DARK[0], CSS_TEMPLATE_DARK[1], CSS_TEMPLATE_DARK[2], CSS_TEMPLATE_DARK[3], CSS_TEMPLATE_DARK[4]);
}
Files.WriteFile(css, htmlElements);
}
}