29a0f32b6404e6b1c0822e6e45d11b6783601905
1 package be
.nikiroo
.fanfix
.output
;
4 import java
.io
.FileWriter
;
5 import java
.io
.IOException
;
7 import be
.nikiroo
.fanfix
.Instance
;
8 import be
.nikiroo
.fanfix
.bundles
.StringId
;
9 import be
.nikiroo
.fanfix
.data
.Chapter
;
10 import be
.nikiroo
.fanfix
.data
.Paragraph
;
11 import be
.nikiroo
.fanfix
.data
.Paragraph
.ParagraphType
;
12 import be
.nikiroo
.fanfix
.data
.Story
;
13 import be
.nikiroo
.utils
.StringUtils
;
15 class Html
extends BasicOutput
{
16 protected FileWriter writer
;
17 private boolean inDialogue
= false;
18 private boolean inNormal
= false;
21 public File
process(Story story
, File targetDir
, String targetName
)
23 File target
= new File(targetDir
, targetName
);
26 targetName
= new File(targetName
, "index").getPath();
28 String targetNameOrig
= targetName
;
29 targetName
+= getDefaultExtension();
31 target
= new File(targetDir
, targetName
);
33 writer
= new FileWriter(target
);
35 super.process(story
, targetDir
, targetNameOrig
);
45 public String
getDefaultExtension() {
50 protected void writeStoryHeader(Story story
) throws IOException
{
52 if (story
.getMeta() != null) {
53 title
= story
.getMeta().getTitle();
56 writer
.write("<!DOCTYPE html>");
57 writer
.write("\n<html>");
58 writer
.write("\n<head>");
59 writer
.write("\n <meta http-equiv='content-type' content='text/html; charset=utf-8'>");
60 writer
.write("\n <meta name='viewport' content='width=device-width, initial-scale=1.0'>");
61 writer
.write("\n <title>" + StringUtils
.xmlEscape(title
) + "</title>");
62 writer
.write("\n</head>");
63 writer
.write("\n<body>\n");
65 writer
.write("<h1>" + StringUtils
.xmlEscape(title
) + "</h1>\n\n");
69 protected void writeStoryFooter(Story story
) throws IOException
{
70 writer
.write("</body>\n");
74 protected void writeChapterHeader(Chapter chap
) throws IOException
{
76 if (chap
.getName() != null && !chap
.getName().isEmpty()) {
77 txt
= Instance
.getTrans().getString(StringId
.CHAPTER_NAMED
,
78 chap
.getNumber(), chap
.getName());
80 txt
= Instance
.getTrans().getString(StringId
.CHAPTER_UNNAMED
,
84 writer
.write("<h1>" + StringUtils
.xmlEscape(txt
) + "</h1>\n\n");
91 protected void writeParagraphHeader(Paragraph para
) throws IOException
{
92 if (para
.getType() == ParagraphType
.QUOTE
&& !inDialogue
) {
93 writer
.write(" <div class='dialogues'>\n");
95 } else if (para
.getType() != ParagraphType
.QUOTE
&& inDialogue
) {
96 writer
.write(" </div>\n");
100 if (para
.getType() == ParagraphType
.NORMAL
&& !inNormal
) {
101 writer
.write(" <div class='normals'>\n");
103 } else if (para
.getType() != ParagraphType
.NORMAL
&& inNormal
) {
104 writer
.write(" </div>\n");
108 switch (para
.getType()) {
110 writer
.write(" <div class='blank'></div>");
113 writer
.write(" <hr/>");
116 writer
.write(" <span class='normal'>");
119 writer
.write(" <div class='dialogue'>— ");
123 writer
.write("<a href='"
124 + StringUtils
.xmlEscapeQuote(para
.getContent()) + "'>"
125 + StringUtils
.xmlEscape(para
.getContent()) + "</a>");
131 protected void writeParagraphFooter(Paragraph para
) throws IOException
{
132 switch (para
.getType()) {
134 writer
.write("</span>\n");
137 writer
.write("</div>\n");
146 protected void writeTextLine(ParagraphType type
, String line
)
151 writer
.write(decorateText(StringUtils
.xmlEscape(line
)));
159 protected String
enbold(String word
) {
160 return "<strong>" + word
+ "</strong>";
164 protected String
italize(String word
) {
165 return "<emph>" + word
+ "</emph>";