From 9159426ee11be9d363955b15e4d91f13e2595431 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Tue, 1 Dec 2020 19:27:25 +0100 Subject: Update handling of "despammed" email addresses. Support a new element, support a "nolink" attribute on the element, interchange and elements on output. --- org/madore/damlengine/TodoElement.java | 1 + org/madore/damlengine/TodoEmailAtOrDotElement.java | 14 +++++++------ .../damlengine/TodoEmailDespammedElement.java | 24 ++++++++++++++++------ org/madore/damlengine/TodoFooter.java | 4 +++- 4 files changed, 30 insertions(+), 13 deletions(-) (limited to 'org') diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index 0cc7880..818fe2b 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -46,6 +46,7 @@ public abstract class TodoElement extends TodoItem { damlFactories.put("email-despammed", new TodoEmailDespammedElement.Factory()); damlFactories.put("email-at", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.AT)); damlFactories.put("email-dot", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.DOT)); + damlFactories.put("email-plus", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.PLUS)); damlFactories.put("extra-style", new TodoExtraStyleOrScriptElement.Factory(TodoStyleOrScript.Type.STYLE)); damlFactories.put("extra-script", new TodoExtraStyleOrScriptElement.Factory(TodoStyleOrScript.Type.SCRIPT)); damlFactories.put("smiley-smile", new TodoSmileyElement.Factory(TodoSmileyElement.Type.SMILE)); diff --git a/org/madore/damlengine/TodoEmailAtOrDotElement.java b/org/madore/damlengine/TodoEmailAtOrDotElement.java index 6597291..e970264 100644 --- a/org/madore/damlengine/TodoEmailAtOrDotElement.java +++ b/org/madore/damlengine/TodoEmailAtOrDotElement.java @@ -6,7 +6,12 @@ public final class TodoEmailAtOrDotElement extends TodoDefaultElement { public enum Type { AT("commercial-at", "commercial_at.png", "at sign", "arobase"), - DOT("full-stop", "full_stop.png", "dot", "point"); + DOT("full-stop", "full_stop.png", "dot", "point"), + PLUS("plus-sign", "plus_sign.png", "plus", "plus"); + // Images generated with: + // convert -size 16x20 'xc:transparent' -font 'Source-Code-Pro' -pointsize 20 -gravity South -annotate 0 '@' ~/public_html/images/commercial_at.png + // convert -size 16x20 'xc:transparent' -font 'Source-Code-Pro' -pointsize 20 -gravity South -annotate 0 '.' ~/public_html/images/full_stop.png + // convert -size 16x20 'xc:transparent' -font 'Source-Code-Pro' -pointsize 20 -gravity South -annotate 0 '+' ~/public_html/images/plus_sign.png final String charName; final String imgName; final String enName; @@ -59,16 +64,13 @@ public final class TodoEmailAtOrDotElement extends TodoDefaultElement { LangHelper.setLangNorec(span0, expLang); span0.setAttributeNS(null, "class", "replace-"+t.charName); node.getParentNode().replaceChild(span0, node); - Element span1 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "span"); - span1.setAttributeNS(null, "class", "subreplace-"+t.charName); - span0.appendChild(span1); Element img = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "img"); img.setAttributeNS(null, "src", (ctx.gc.uriToTop==null?"":ctx.gc.uriToTop)+"images/"+t.imgName); img.setAttributeNS(null, "alt", "["+(lang.equals("fr")?t.frName:t.enName)+"]"); - img.setAttributeNS(null, "height", "15"); + img.setAttributeNS(null, "height", "20"); img.setAttributeNS(null, "width", "16"); - span1.appendChild(img); + span0.appendChild(img); } } diff --git a/org/madore/damlengine/TodoEmailDespammedElement.java b/org/madore/damlengine/TodoEmailDespammedElement.java index 9d393ed..fdeb0d5 100644 --- a/org/madore/damlengine/TodoEmailDespammedElement.java +++ b/org/madore/damlengine/TodoEmailDespammedElement.java @@ -23,24 +23,36 @@ public final class TodoEmailDespammedElement extends TodoDefaultElement { @Override public void handleNodeOnly() { Element out0 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "code"); + Element out; + if ( node.getAttributeNS(null, "nolink").equals("") ) { + out = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a"); + out.appendChild(out0); + out.setAttributeNS(null, "class", "despammed-address"); + } else + out = out0; String lang = LangHelper.getLangNorec(node); if ( lang != null ) - LangHelper.setLangNorec(out0, lang); - Element out1 = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "a"); - out0.appendChild(out1); - out1.setAttributeNS(null, "class", "despammed-address"); + LangHelper.setLangNorec(out, lang); + { + String classAtt = node.getAttributeNS(null, "class"); + if ( ! classAtt.equals("") ) + out0.setAttributeNS(null, "class", + "despammed-email "+classAtt); + else + out0.setAttributeNS(null, "class", "despammed-email"); + } ArrayList childList = getChildList(node); ArrayList toProcess = new ArrayList(childList.size()+8); for ( Node child : childList ) { - out1.appendChild(child); + out.appendChild(child); if ( child.getNodeType() == Node.ELEMENT_NODE ) { TodoElement it = TodoElement.getTodoElement((Element)child, this.ctx, this); toProcess.add(it); } } - node.getParentNode().replaceChild(out0, node); + node.getParentNode().replaceChild(out, node); this.ownerDeque.registerAtStart(toProcess); } diff --git a/org/madore/damlengine/TodoFooter.java b/org/madore/damlengine/TodoFooter.java index ca46a83..90d4f5f 100644 --- a/org/madore/damlengine/TodoFooter.java +++ b/org/madore/damlengine/TodoFooter.java @@ -38,7 +38,9 @@ public final class TodoFooter extends TodoElement { addr.appendChild(ctx.doc.createTextNode(" (")); Element email = ctx.doc.createElementNS(DamlEngine.DAML_NS, "d:email-despammed"); addr.appendChild(email); - email.appendChild(ctx.doc.createTextNode("david+www")); + email.appendChild(ctx.doc.createTextNode("david")); + email.appendChild(ctx.doc.createElementNS(DamlEngine.DAML_NS, "d:email-plus")); + email.appendChild(ctx.doc.createTextNode("www")); email.appendChild(ctx.doc.createElementNS(DamlEngine.DAML_NS, "d:email-at")); email.appendChild(ctx.doc.createTextNode("madore")); email.appendChild(ctx.doc.createElementNS(DamlEngine.DAML_NS, "d:email-dot")); -- cgit v1.2.3