OSDN Git Service

Added LaTex image insert & edit
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / xml / NoteFormatter.java
index 81229f1..1da2050 100644 (file)
@@ -204,7 +204,7 @@ public class NoteFormatter {
        }\r
        \r
     // Modify the en-media tag into an image tag so it can be displayed.\r
        }\r
        \r
     // Modify the en-media tag into an image tag so it can be displayed.\r
-    private void modifyImageTags(QDomElement docElem, QDomElement enmedia, QDomAttr hash) {\r
+    private void modifyImageTags(QDomDocument doc, QDomElement docElem, QDomElement enmedia, QDomAttr hash) {\r
        logger.log(logger.HIGH, "Entering NeverNote.modifyImageTags");\r
        String type = enmedia.attribute("type");\r
        if (type.startsWith("image/"))\r
        logger.log(logger.HIGH, "Entering NeverNote.modifyImageTags");\r
        String type = enmedia.attribute("type");\r
        if (type.startsWith("image/"))\r
@@ -243,10 +243,23 @@ public class NoteFormatter {
 //             enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());\r
                enmedia.setAttribute("src", tfile.fileName().toString());\r
                enmedia.setAttribute("en-tag", "en-media");\r
 //             enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());\r
                enmedia.setAttribute("src", tfile.fileName().toString());\r
                enmedia.setAttribute("en-tag", "en-media");\r
-               enmedia.setAttribute("onContextMenu", "window.jambi.imageContextMenu('" +tfile.fileName()  +"');");\r
+               enmedia.setTagName("img");\r
+               if (r.getAttributes().getSourceURL() == null || !r.getAttributes().getSourceURL().toLowerCase().startsWith("http://latex.codecogs.com/gif.latex?"))\r
+                       enmedia.setAttribute("onContextMenu", "window.jambi.imageContextMenu('" +tfile.fileName()  +"');");\r
+               else {\r
+                       QDomElement newText = doc.createElement("a");\r
+                       enmedia.setAttribute("src", tfile.fileName().toString());\r
+                       enmedia.setAttribute("en-tag", "en-latex");\r
+                       newText.setAttribute("onMouseOver", "style.cursor='hand'");\r
+                       newText.setAttribute("title", r.getAttributes().getSourceURL());\r
+                       newText.setAttribute("href", "latex://"+tfile.fileName().toString());\r
+                       enmedia.parentNode().replaceChild(newText, enmedia);\r
+                       newText.appendChild(enmedia);\r
+\r
+               }\r
                enmedia.setNodeValue("");\r
                enmedia.setAttribute("guid", resGuid);\r
                enmedia.setNodeValue("");\r
                enmedia.setAttribute("guid", resGuid);\r
-               enmedia.setTagName("img");\r
+\r
 \r
                logger.log(logger.HIGH, "Leaving NeverNote.modifyImageTags");\r
     }\r
 \r
                logger.log(logger.HIGH, "Leaving NeverNote.modifyImageTags");\r
     }\r
@@ -273,7 +286,7 @@ public class NoteFormatter {
                                \r
                                if (type[0] != null) {\r
                                        if (type[0].equals("image")) {\r
                                \r
                                if (type[0] != null) {\r
                                        if (type[0].equals("image")) {\r
-                                               modifyImageTags(docElem, enmedia, hash);\r
+                                               modifyImageTags(doc, docElem, enmedia, hash);\r
                                        }\r
                                        if (!type[0].equals("image")) {\r
                                                modifyApplicationTags(doc, docElem, enmedia, hash, appl);\r
                                        }\r
                                        if (!type[0].equals("image")) {\r
                                                modifyApplicationTags(doc, docElem, enmedia, hash, appl);\r
@@ -324,7 +337,11 @@ public class NoteFormatter {
                enCryptLen = anchors.length();\r
                for (int i=0; i<anchors.length(); i++) {\r
                        QDomElement element = anchors.at(i).toElement();\r
                enCryptLen = anchors.length();\r
                for (int i=0; i<anchors.length(); i++) {\r
                        QDomElement element = anchors.at(i).toElement();\r
-                       element.setAttribute("title", element.attribute("href"));\r
+                       if (!element.attribute("href").toLowerCase().startsWith("latex://"))\r
+                               element.setAttribute("title", element.attribute("href"));\r
+                       else {\r
+                               element.setAttribute("title", element.attribute("title").toLowerCase().replace("http://latex.codecogs.com/gif.latex?",""));\r
+                       }\r
                }\r
 \r
                logger.log(logger.HIGH, "Leaving NeverNote.modifyTags");\r
                }\r
 \r
                logger.log(logger.HIGH, "Leaving NeverNote.modifyTags");\r