Add URL footnotes
authorNiki Roo <niki@nikiroo.be>
Thu, 22 Mar 2018 15:59:09 +0000 (16:59 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 22 Mar 2018 15:59:09 +0000 (16:59 +0100)
src/be/nikiroo/gofetch/support/BasicSupport.java

index 1258e8918ad1ec8eb429849634aa5f950bdc674f..4067979d4dc1b3f1657189be91d85ec8cec345c0 100644 (file)
@@ -256,6 +256,7 @@ public abstract class BasicSupport {
                final StringBuilder currentLine = new StringBuilder();
                final List<Integer> quoted = new ArrayList<Integer>();
                final List<Node> ignoredNodes = new ArrayList<Node>();
+               final List<String> footnotes = new ArrayList<String>();
 
                if (element != null) {
                        new NodeTraversor(new NodeVisitor() {
@@ -313,6 +314,11 @@ public abstract class BasicSupport {
                                                if (block && currentLine.length() > 0) {
                                                        currentLine.append("\n");
                                                }
+
+                                               if (!element.absUrl("href").trim().isEmpty()) {
+                                                       footnotes.add(element.absUrl("href"));
+                                                       currentLine.append("[" + footnotes.size() + "]");
+                                               }
                                        } else if (node instanceof TextNode) {
                                                TextNode textNode = (TextNode) node;
                                                String line = StringUtil.normaliseWhitespace(textNode
@@ -349,6 +355,16 @@ public abstract class BasicSupport {
                        lines.set(i, lines.get(i).replace("  ", " ").trim());
                }
 
+               if (footnotes.size() > 0) {
+                       lines.add("");
+                       lines.add("");
+                       lines.add("");
+                       lines.add("");
+                       for (int i = 0; i < footnotes.size(); i++) {
+                               lines.add("[" + (i + 1) + "] " + footnotes.get(i));
+                       }
+               }
+
                return lines;
        }
 }