Html output: add a <pre> and some align=justify
[gofetch.git] / src / be / nikiroo / gofetch / output / Html.java
index b0ef7e2e834698b66791fdbf6784ece99d935200..cdc77a461056887ef1cafad7e6abf7d19019d1ab 100644 (file)
@@ -17,14 +17,21 @@ public class Html extends Output {
                }
 
                String gopherUrl = "gopher://" + hostname + sel + ":" + port;
+               
+               StringBuilder builder = new StringBuilder();
+               appendPre(builder);
 
-               return "<h1>News</h1>\n"//
+               builder.append("<h1>News</h1>\n"//
                                + "<p>You will find here a few pages full of news, mirroring <a href='"
                                + gopherUrl + "'>"
                                + gopherUrl
                                + "</a>.</p>\n"//
                                + "<p>They are simply scrapped from their associated webpage and updated a few times a day.</p>\n"//
-               ;
+               );
+               
+               appendPost(builder);
+               
+               return builder.toString();
        }
 
        @Override
@@ -36,17 +43,22 @@ public class Html extends Output {
        public String exportHeader(Story story) {
                StringBuilder builder = new StringBuilder();
 
+               appendPre(builder);
+
                builder.append("<div class='story-header'>\n");
                appendHtml(builder, story, true);
                builder.append("<hr/>\n");
                builder.append("</div>\n");
 
+               appendPost(builder);
+
                return builder.toString();
        }
 
        @Override
        public String export(Story story) {
                StringBuilder builder = new StringBuilder();
+               appendPre(builder);
 
                builder.append("<div class='story'>\n");
                appendHtml(builder, story, false);
@@ -60,13 +72,31 @@ public class Html extends Output {
 
                builder.append("</div>\n");
 
+               appendPost(builder);
+
                return builder.toString();
        }
 
+       private void appendPre(StringBuilder builder) {
+               builder.append("<!DOCTYPE html>\n");
+               builder.append("<html>\n");
+               builder.append("<head>\n");
+               builder.append("  <meta http-equiv='content-type' content='text/html; charset=utf-8'>\n");
+               builder.append("  <meta name='viewport' content='width=device-width, initial-scale=1.0'>\n");
+               builder.append("  <style type='text/css'>\n");
+               builder.append("    body { margin: 1em 15%; }\n");
+               builder.append("  </style>\n");
+               builder.append("</head>\n");
+               builder.append("<body>\n");
+       }
+
+       private void appendPost(StringBuilder builder) {
+               builder.append("</body>\n");
+       }
+
        private void appendHtml(StringBuilder builder, Comment comment, String space) {
-               builder.append(space).append(
-                               "<div class='comment' style='display: block; margin-left: "
-                                               + (20 * space.length()) + "px'>");
+               builder.append(space)
+                               .append("<div class='comment' style='display: block; margin-left: 80px'>\n");
                builder.append(space).append("  <h2>").append(comment.getTitle())
                                .append("</h2>\n");
                builder.append(space).append("  <div class='by'>")
@@ -76,7 +106,7 @@ public class Html extends Output {
                for (Comment subComment : comment) {
                        appendHtml(builder, subComment, space + "  ");
                }
-               builder.append(space).append("</div>");
+               builder.append(space).append("</div>\n");
        }
 
        private StringBuilder appendHtml(StringBuilder builder, Story story,
@@ -103,7 +133,7 @@ public class Html extends Output {
                        builder.append("        <br/>\n");
                }
 
-               builder.append("        <div class='content'>\n");
+               builder.append("        <div class='content' style='text-align: justify'>\n");
                if (resume) {
                        builder.append("                " + story.getContent() + "\n");
                } else {