HTML style change (author in italics)
[gofetch.git] / src / be / nikiroo / gofetch / output / Html.java
index fea5f67997c0b36ad3f45734051a32ce6d16d911..50fe2d7fac8848e50c2efe41929567e2fa92c15c 100644 (file)
@@ -1,7 +1,5 @@
 package be.nikiroo.gofetch.output;
 
-import java.util.List;
-
 import be.nikiroo.gofetch.data.Comment;
 import be.nikiroo.gofetch.data.Story;
 import be.nikiroo.gofetch.support.BasicSupport.Type;
@@ -17,16 +15,23 @@ public class Html extends Output {
                if (!sel.isEmpty()) {
                        sel = "/1" + sel;
                }
-               
+
                String gopherUrl = "gopher://" + hostname + sel + ":" + port;
 
-               return "<h1>News</h1>\n"//
+               StringBuilder builder = new StringBuilder();
+               appendPre(builder);
+
+               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
@@ -35,50 +40,76 @@ public class Html extends Output {
        }
 
        @Override
-       public String export(Story story) {
+       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, List<Comment> comments) {
+       public String export(Story story) {
                StringBuilder builder = new StringBuilder();
+               appendPre(builder);
 
                builder.append("<div class='story'>\n");
                appendHtml(builder, story, false);
                builder.append("<hr/>\n");
 
-               if (comments != null) {
-                       for (Comment comment : comments) {
+               if (story.getComments() != null) {
+                       for (Comment comment : story.getComments()) {
                                appendHtml(builder, comment, "  ");
                        }
                }
 
                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'>")
+               builder.append(space).append("  <div class='by' style='font-style: italic;'>")
                                .append(comment.getAuthor()).append("</div>\n");
-               builder.append(space).append("  <div class='comment_content'>")
-                               .append(comment.getContent()).append("</div>\n");
+               builder.append(space).append("  <div class='comment_content'>");
+               for (String line : comment.getContentLines()) {
+                       builder.append("<p>" + line + "</p>");
+               }
+               builder.append("</div>\n");
                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,
@@ -89,8 +120,12 @@ public class Html extends Output {
                } else {
                        builder.append("        <h1>" + story.getTitle() + "</h1>\n");
                }
-               builder.append("        <div class='details'>(" + story.getDetails()
-                               + ")</div>\n");
+
+               builder.append("        <div class='details'>");
+               if (story.getDetails() != null && !story.getDetails().isEmpty()) {
+                       builder.append("(").append(story.getDetails()).append(")");
+               }
+               builder.append("</div>\n");
                builder.append("        <br/>\n");
 
                if (!resume) {
@@ -105,8 +140,15 @@ public class Html extends Output {
                        builder.append("        <br/>\n");
                }
 
-               builder.append("        <div class='content'>\n");
-               builder.append("                " + story.getContent() + "\n");
+               builder.append("        <div class='content' style='text-align: justify'>\n");
+               if (resume) {
+                       builder.append("                " + story.getContent() + "\n");
+               } else {
+                       builder.append("                "
+                                       + story.getFullContent().replace("\n", "<br/>")
+                                                       .replace("[ ", "<h2>").replace(" ]", "</h2>")
+                                       + "\n");
+               }
                builder.append("        </div>\n");
 
                return builder;