in src/main/java/ConvertHtml2Adoc.java [100:229]
private static void postConvert(File dst) {
BufferedReader br;
BufferedWriter bw;
String s;
File tempDst = Paths.get(dst.toString() + ".tmp").toFile();
dst.renameTo(tempDst);
try {
bw = new BufferedWriter(new FileWriter(dst, true));
try {
br = new BufferedReader(new FileReader(tempDst));
// Write new header
bw.write(header());
// Skip old header
while((s = br.readLine()) != null) {
if (s.startsWith("[[contentBox]]")) {
break;
}
}
while((s = br.readLine()) != null) {
// System.out.println("Checking: " + s);
if (s.contains("[[footer]]")) {
// skip footer and everything after it.
break;
}
if (s.contains("'''''")) {
// weird ''''' at ends of files
break;
}
// Move headers up by one level
if (s.startsWith("===")) {
s = s.substring(1);
}
// Handle select/option in 'release' files
// if (s.contains("<select name=")) {
// if (true) throw new IllegalStateException();
// s = s.substring(0, s.indexOf("<select "));
// bw.write(s + NL);
// bw.write(NL);
// s = br.readLine();
// int pos;
// while ((pos = s.indexOf("<option ")) >= 0) {
// pos = s.indexOf(">", pos);
// s = s.substring(pos + 1);
// pos = s.indexOf("</option>");
// String w = s.substring(0, pos);
// bw.write("* " + w);
// }
// }
if (s.startsWith("http://apache.mirror.anlx.net/")) {
bw.write(selectForm() + NL);
//skip next line
br.readLine();
continue;
}
//Lines 1 and 2:
// TODO ? Replace Images:
//link:./[image:images/JDOx150.gif[Apache JDO]]
//link:./[image:images/jdo_text.gif[Apache JDO]]
//image:images/JDOx150.gif[Apache JDO]
//image:images/jdo_text.gif[Apache JDO]
// Fix external links, except for actual javadoc html pages
// if (!s.contains("-javadoc/index.html")) {
// s = s.replace(".html", ".adoc");
// }
// Fix internal crossrefs
s = s.replace("link:#", "xref:");
// Fix GIF not supported:
s = s.replace(".gif", ".png");
// Fix empty lines
// see https://github.com/asciidoctor/asciidoctor/wiki/How-to-insert-sequential-blank-lines
if (s.equals(" +")) {
s = "{empty} +\n";
bw.write(s + NL);
continue;
}
// Fix crossref targets/anchors
// INPUT:
//[#PersistenceCapable]##
//==== @PersistenceCapable[#aPersistenceCapable]####
// OUPUT:
//anchor:anchor-2[]
while (s.contains("[#")) {
int pos1 = s.indexOf("[#");
int pos2 = s.indexOf("]", pos1+1);
String post = "[" + s.substring(pos2);
if (pos1 > 0) {
s = s.substring(0, pos1) + "anchor:" + s.substring(pos1+2, pos2) + post;
} else {
s = "anchor:" + s.substring(2, pos2) + post;
}
}
// some more hacks:
s = s.endsWith("]##") ? s.substring(0, s.lastIndexOf(']') + 1) : s;
s = s.endsWith("]####") ? s.substring(0, s.lastIndexOf(']') + 1) : s;
// Fixes glossary.html
int pos = s.indexOf("]####");
if (pos >=0) {
s = s.substring(0, pos + 1) + s.substring(pos + 5);
}
bw.write(s + NL);
}
br.close();
} catch(FileNotFoundException e) {
System.out.println("File was not found!");
} catch(IOException e) {
System.out.println("No file found!");
}
bw.close();
} catch(FileNotFoundException e) {
System.out.println("Error1!");
} catch(IOException e) {
System.out.println("Error2!");
}
tempDst.delete();
}