appendix implementation enabled + fixed

This commit is contained in:
stfm
2012-06-25 22:39:49 +02:00
parent 487a48e0ca
commit 50e7442d35
4 changed files with 69 additions and 44 deletions

View File

@@ -24,9 +24,16 @@ import javax.swing.text.html.parser.ParserDelegator;
import com.keypoint.PngEncoder; import com.keypoint.PngEncoder;
/** /**
* <p>
* This class implements a <CODE>ParserCallback</CODE> that translates HTML to * This class implements a <CODE>ParserCallback</CODE> that translates HTML to
* the corresponding <TEX txt="\LaTeX{}">LaTeX</TEX>. Not all tags a processed * the corresponding <TEX txt="\LaTeX{}">LaTeX</TEX>. Not all tags a processed
* but the most common are. * but the most common are.
* <p>
* HTML links to files located in the doc-files directory (<a
* href="doc-files/appendix_a.html">appendix_a.html</a>, <a
* href="doc-files/appendix_b.txt">appendix_b.txt</a>) are transformed to
* references to the appendix, whereby the referenced files itself are included
* in the appendix.
* *
* @see javax.swing.text.html.parser.ParserDelegator * @see javax.swing.text.html.parser.ParserDelegator
* @author Soeren Caspersen * @author Soeren Caspersen
@@ -250,35 +257,37 @@ public class HTMLtoLaTeXBackEnd extends HTMLEditorKit.ParserCallback {
doPrintURL = (String) attrSet.getAttribute("doprinturl"); doPrintURL = (String) attrSet.getAttribute("doprinturl");
if (refurl != null) { if (refurl != null) {
if (TeXDoclet.hyperref) { if (TeXDoclet.hyperref) {
// if (refurl.toLowerCase().startsWith("doc-files")) { if (refurl.toLowerCase().startsWith("doc-files")) {
// File file = new File(TeXDoclet.packageDir, refurl); File file = new File(TeXDoclet.packageDir, refurl);
// if (file.exists()) { if (file.exists()) {
// if (TeXDoclet.appendencies.contains(file.getPath())) { if (TeXDoclet.appendencies.contains(file.getPath())) {
// refurl = (String) TeXDoclet.appendencies refurl = (String) TeXDoclet.appendencies
// .get(file.getPath()); .get(file.getPath());
// } else { } else {
// refurl = "appendix" refurl = "appendix"
// + new Integer( + new Integer(
// TeXDoclet.appendencies.size() + 1); TeXDoclet.appendencies.size() + 1);
// TeXDoclet.appendencies.put(file.getPath(), TeXDoclet.appendencies.put(file.getPath(),
// refurl); refurl);
// } }
// ret.append("\\hyperref{}{" + refurl + "}{}{"); ret.append("{");
// return; return;
// }
// }
String sharp = "";
if (refurl.indexOf("#") >= 0) {
sharp = refurl.substring(refurl.indexOf("#") + 1,
refurl.length());
if (sharp.indexOf("%") >= 0) {
sharp = ""; // Don't know what to do with '%'
} }
refurl = refurl.substring(0, refurl.indexOf("#")); } else {
String sharp = "";
if (refurl.indexOf("#") >= 0) {
sharp = refurl.substring(refurl.indexOf("#") + 1,
refurl.length());
if (sharp.indexOf("%") >= 0) {
sharp = ""; // Don't know what to do with '%'
}
refurl = refurl.substring(0, refurl.indexOf("#"));
}
ret.append("\\hyperref{" + refurl + "}{" + sharp
+ "}{}{");
// ret.append("\\href{" + refurl + "}{");
} }
ret.append("\\hyperref{" + refurl + "}{" + sharp + "}{}{");
// ret.append("\\href{" + refurl + "}{");
} else { } else {
ret.append("{\\bf "); ret.append("{\\bf ");
} }
@@ -392,6 +401,15 @@ public class HTMLtoLaTeXBackEnd extends HTMLEditorKit.ParserCallback {
ret.append("}"); ret.append("}");
} else if (tag == HTML.Tag.A) { } else if (tag == HTML.Tag.A) {
if (refurl != null) { if (refurl != null) {
if (refurl.startsWith("appendix")) {
ret.append("\\refdefined{" + refurl + "}");
ret.append("}");
return;
}
ret.append("}"); ret.append("}");
if (doPrintURL != null) { if (doPrintURL != null) {
if (!refurl.equals("")) { if (!refurl.equals("")) {
@@ -400,6 +418,7 @@ public class HTMLtoLaTeXBackEnd extends HTMLEditorKit.ParserCallback {
ret.append(")"); ret.append(")");
} }
} }
} else if (refname != null) { } else if (refname != null) {
ret.append("}"); ret.append("}");
} }

View File

@@ -213,7 +213,8 @@ public class TeXDoclet extends Doclet {
System.out.println("command to execute : " + "javadoc " System.out.println("command to execute : " + "javadoc "
+ argsString); + argsString);
// TODO something goes wrong here. javadoc always prints help output // TODO something goes wrong here. javadoc always prints help
// output.
Process p = Runtime.getRuntime().exec("javadoc", argsJd); Process p = Runtime.getRuntime().exec("javadoc", argsJd);
p.waitFor(); p.waitFor();
@@ -675,23 +676,25 @@ public class TeXDoclet extends Doclet {
os.println("}"); os.println("}");
} }
// if (appendencies.size() > 0) { if (appendencies.size() > 0) {
// os.println("\\appendix"); os.println("\\appendix");
// Iterator it = appendencies.keySet().iterator(); Iterator it = appendencies.keySet().iterator();
// while (it.hasNext()) { int i = 0;
// os.println(" \\chapter{" + (char) ('A' + 1) while (it.hasNext()) {
// + "}\n\\hyperdef{appendix1}{}"); os.println("\\" + sectionLevels[0] + "{}{");
// os.println(" \\hyperdef{appendix1}{}sdafafdasd"); os.println(" \\label{appendix" + (i + 1) + "}");
// String sfa = (String) it.next(); String sfa = (String) it.next();
// System.out.println(sfa); // System.out.println(sfa);
// addFile(os, sfa, true); addFile(os, sfa, true);
// } os.println("}");
// } i++;
}
}
// os.println("\\markboth{}{}"); os.println("\\markboth{}{}");
// if (index) { if (index) {
// os.println("\\printindex"); os.println("\\printindex");
// } }
addFile(os, finishFile, false); addFile(os, finishFile, false);

View File

@@ -0,0 +1,2 @@
<h2>Appendix A content</h2>
content of file doc-files/appendix_a.html

View File

@@ -0,0 +1 @@
content of file doc-files/appendix_b.txt