From 4f098971956cb68fbe5b39dd43136e27d0dfa832 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Wed, 16 Sep 2015 21:35:44 +0800 Subject: [PATCH] Add css support to our dictionary! --- .../java/im/darkgeek/dicts/Converter.java | 7 ++ .../java/im/darkgeek/dicts/DictGenerator.java | 75 ++++++++++++++++++- .../java/im/darkgeek/dicts/DictProcessor.java | 4 +- 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/main/java/im/darkgeek/dicts/Converter.java b/src/main/java/im/darkgeek/dicts/Converter.java index c76837a..397f034 100644 --- a/src/main/java/im/darkgeek/dicts/Converter.java +++ b/src/main/java/im/darkgeek/dicts/Converter.java @@ -105,6 +105,12 @@ public int process(Element element) { return 1; } }; + Callback changeToH1 = new Callback() { + public int process(Element element) { + element.setName("h2"); + return 1; + } + }; System.setProperty("entityExpansionLimit", "640000"); System.out.println(System.getProperty("user.dir")); @@ -121,6 +127,7 @@ public int process(Element element) { .addQuirk("er", changeToHypeLink) .addQuirk("qau", enhanceQAUblock) .addQuirk("au", enhanceQAUblock) + .addQuirk("ent", changeToH1) .generate(); System.out.println("Size: " + list.size()); DictGenerator.createGeneratorScript(list); diff --git a/src/main/java/im/darkgeek/dicts/DictGenerator.java b/src/main/java/im/darkgeek/dicts/DictGenerator.java index 75fc7dd..e582cf7 100644 --- a/src/main/java/im/darkgeek/dicts/DictGenerator.java +++ b/src/main/java/im/darkgeek/dicts/DictGenerator.java @@ -14,7 +14,68 @@ public class DictGenerator { "with slob.create('gcide.slob') as w:\n"; private static String GENERATOR_TEMPLATE = " w.add(\"\"\"#DEFINATION#\"\"\".encode('utf-8'), \"\"\"#WORD#\"\"\", content_type='text/html; charset=utf-8')"; - private static final String SCRIPT_NAME = "dict_creator.py"; + private static String nightModeCss = "body {\n" + + " background-color: black;\n" + + " color: gray;\n" + + "}\n" + + "\n" + + "h1, h2, h3, h4, h5, h6 {\n" + + " color: gray !important;\n" + + "}\n" + + "\n" + + "img {\n" + + " background-color: lightgray;\n" + + "}\n" + + "\n" + + "table {\n" + + " background-color: black !important;\n" + + " color: gray !important;\n" + + "}\n" + + "\n" + + "div.thumbinner {\n" + + " background-color: #191919 !important;\n" + + "}\n" + + "\n" + + "div.thumb {\n" + + " border-color: black !important;\n" + + "}\n" + + "\n" + + "a {\n" + + " color: green;\n" + + "}\n" + + "\n" + + "a:visited {\n" + + " color: darkgreen;\n" + + "}\n"; + private static String nightModeCssLink = ""; + private static String defaultCss = "pos {\n" + + "\tcolor: darkgreen;\n" + + "\tfont-weight: bold;\n" + + "}\n" + + "\n" + + "hw,sn {\n" + + "\tfont-weight: bold;\n" + + "}\n" + + "\n" + + "q,it,ant,asp,booki,causedby,cnvto,compof,\n" + + "contr,cref,film,fld,itran,itrans,abbr,altname,altnpluf,\n" + + "ets,etsep,ex,mark,qex,sd,ship,source,pluf,uex,isa,mathex,\n" + + "ratio,singf,xlati,tran,tr,iref,figref,ptcl,title,stype,\n" + + "part,parts,membof,member,members,corr,qperson,prod,prodmac,\n" + + "stage,inv,methodfor,examp,unit,uses,usedby,perf,recipr,sig,wns,\n" + + "w16ns,spn,kingdom,phylum,subphylum,class,subclass,ord,subord,\n" + + "suborder,fam,subfam,gen,var,varn\n" + + "{\n" + + "\tfont-style: italic;\n" + + "}\n" + + "\n" + + "qau,au {\n" + + "\tfont-style: italic;\n" + + " font-weight: bold;\n" + + "}"; + private static String defaultCssLink = ""; + private static String SCRIPT_NAME = "dict_creator.py"; public static void createGeneratorScript(List items) { if (items == null) @@ -25,11 +86,21 @@ public static void createGeneratorScript(List items) { printWriter = new PrintWriter(SCRIPT_NAME, "UTF-8"); printWriter.print(GENERATOR_SCRIPT_HEADER); + printWriter.println( + GENERATOR_TEMPLATE + .replace("#DEFINATION#", nightModeCss) + .replace("#WORD#", "~/css/night.css") + ); + printWriter.println( + GENERATOR_TEMPLATE + .replace("#DEFINATION#", defaultCss) + .replace("#WORD#", "~/css/default.css") + ); for (DictItem item : items) { printWriter.println( GENERATOR_TEMPLATE - .replace("#DEFINATION#", item.getExplanation()) + .replace("#DEFINATION#", nightModeCssLink + defaultCssLink + item.getExplanation()) .replace("#WORD#", item.getWord()) ); } diff --git a/src/main/java/im/darkgeek/dicts/DictProcessor.java b/src/main/java/im/darkgeek/dicts/DictProcessor.java index 4f930ef..91b1fe8 100644 --- a/src/main/java/im/darkgeek/dicts/DictProcessor.java +++ b/src/main/java/im/darkgeek/dicts/DictProcessor.java @@ -177,8 +177,8 @@ private boolean isMarkwordOfUnList(String entValue) { private void processLonglistUnPrefixedWords(Element pElement, List itemList, CompoundDictItem unCDictItem) { CompoundDictItem compoundDictItem = new CompoundDictItem(); - String unDefTemplate = "

#WORD#
#WORD#
" + - "#DEFINITION#

"; + String unDefTemplate = "

#WORD#


#WORD#" + + "  -  #DEFINITION#

"; for (Iterator i = pElement.elementIterator(); i.hasNext(); ) { Element currElement = (Element) i.next();