Skip to content

Commit bda1793

Browse files
author
SeTSeR
committed
Fixed export to HTML
1 parent 3a073c4 commit bda1793

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

src/com/temporaryteam/noticeditor/model/NoticeCategory.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.ArrayList;
44

5+
import org.pegdown.PegDownProcessor;
6+
57
import org.json.JSONObject;
68
import org.json.JSONArray;
79
import org.json.JSONException;
@@ -53,6 +55,18 @@ public void setContent(String content) {
5355
this.content = content;
5456
}
5557

58+
public String toHTML(PegDownProcessor processor) {
59+
String html = "";
60+
if((content==null)||(subcategories!=null)) {
61+
for(NoticeCategory category : subcategories) {
62+
html+=("<a href=\"" + category.getName() +".html\">" + category.getName() + ".html</a>");
63+
}
64+
} else {
65+
html+=processor.markdownToHtml(content);
66+
}
67+
return html;
68+
}
69+
5670
public JSONObject toJson() throws JSONException {
5771
JSONObject obj = new JSONObject();
5872
obj.put("name", name);

src/com/temporaryteam/noticeditor/view/NoticeController.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ public void setCurrentTreeItem(NoticeTreeItem newCurrentTreeItem) {
9797
currentTreeItem = newCurrentTreeItem;
9898
}
9999

100+
/**
101+
* Write node
102+
*/
103+
public void writeNode(NoticeCategory node, String name) throws IOException {
104+
File write;
105+
if(openedFile!=null) write = new File(openedFile.getParent() + "/" + name);
106+
else write = chooser.showSaveDialog(main.getPrimaryStage());
107+
if(!write.exists()) write.createNewFile();
108+
FileWriter writeHTML = new FileWriter(write);
109+
writeHTML.write(node.toHTML(processor));
110+
writeHTML.close();
111+
if(node.getSubCategories()!=null) {
112+
for(NoticeCategory subcategory : node.getSubCategories()) {
113+
writeNode(subcategory, (subcategory.getName() + ".html"));
114+
}
115+
}
116+
}
117+
100118
/**
101119
* Rebuild tree
102120
*/
@@ -222,13 +240,7 @@ else if(source.equals(saveAsItem)) {
222240
}
223241
else if(source.equals(exportHTMLItem)) {
224242
try {
225-
String notice = noticeArea.getText();
226-
notice = processor.markdownToHtml(notice);
227-
File selected = chooser.showSaveDialog(main.getPrimaryStage());
228-
if(!selected.exists()) selected.createNewFile();
229-
FileWriter writeFile = new FileWriter(selected);
230-
writeFile.write(notice);
231-
writeFile.close();
243+
writeNode(((NoticeTreeItem)noticeTree.getRoot()).getNotice(), "index.html");
232244
} catch(IOException ioe) {
233245
}
234246
}

0 commit comments

Comments
 (0)