File tree Expand file tree Collapse file tree
src/com/temporaryteam/noticeditor Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import java .util .ArrayList ;
44
5+ import org .pegdown .PegDownProcessor ;
6+
57import org .json .JSONObject ;
68import org .json .JSONArray ;
79import 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 );
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments