OSDN Git Service

proceed implimentation
authorSet <set.minami@gmail.com>
Thu, 30 May 2013 12:56:59 +0000 (21:56 +0900)
committerSet <set.minami@gmail.com>
Thu, 30 May 2013 12:56:59 +0000 (21:56 +0900)
.cache
BlackQuill.opml [new file with mode: 0644]
mdTest/test5.bq
src/main/scala/org/blackquill/engine/BQParser.scala
src/main/scala/org/blackquill/engine/HTMLMap.scala

diff --git a/.cache b/.cache
index e7eacae..e907207 100644 (file)
Binary files a/.cache and b/.cache differ
diff --git a/BlackQuill.opml b/BlackQuill.opml
new file mode 100644 (file)
index 0000000..6614705
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<opml version="1.0">
+    <head>
+        <title>BlackQuill</title>
+        <ownerName></ownerName>
+    </head>
+    <body>
+        <outline text="Manage BlackQuill implementation plan">
+            <outline text="&lt;blockquote>">
+                <outline text="> Ahead Style">
+                    <outline text="A line"></outline>
+                    <outline text="Lines"></outline>
+                </outline>
+            </outline>
+            <outline text="&lt;h1>-&lt;h6>">
+                <outline text="Underline Style">
+                    <outline text="2013/05/E">
+                        <outline text="Done"></outline>
+                    </outline>
+                </outline>
+                <outline text="# ahead Style">
+                    <outline text="2013/05/E">
+                        <outline text="Done"></outline>
+                    </outline>
+                </outline>
+                <outline text="# Surrounded Style">
+                    <outline text="2013/05/E">
+                        <outline text="Done"></outline>
+                    </outline>
+                </outline>
+            </outline>
+            <outline text="&lt;i>">
+                <outline text="Surrounded by * Style">
+                    <outline text="2013/05/E">
+                        <outline text="Done"></outline>
+                    </outline>
+                </outline>
+            </outline>
+            <outline text="&lt;em>">
+                <outline text="Surrounded by ** Style">
+                    <outline text="2013/05/E">
+                        <outline text="Done"></outline>
+                    </outline>
+                </outline>
+            </outline>
+            <outline text="&lt;ul>">
+                <outline text="* Style">
+                    <outline text="2013/05/E">
+                        <outline text="Done"></outline>
+                    </outline>
+                </outline>
+                <outline text="Convert to OPML"></outline>
+            </outline>
+            <outline text="&lt;ol>">
+                <outline text="Numbered Style">
+                    <outline text="2013/05/E">
+                        <outline text="Done"></outline>
+                    </outline>
+                </outline>
+            </outline>
+        </outline>
+    </body>
+</opml>
\ No newline at end of file
index 77edd7d..132fd7e 100644 (file)
@@ -1,7 +1,9 @@
 <Link Href="../Css/Markdown.Css" Type="Text/Css" Rel="Stylesheet"/>
 aaaaaaaa
+-=-=
 bbbbb<-testccccccc
 <hr><br><br>
+
 # TITLE
 ### TITLE2
 <link href="test->test" />
@@ -51,6 +53,59 @@ bbbbb<-testccccccc
             5. E
                 6. F
     7. G
+    
+ * A
+ * B
+  * C
+  * D
+   * E
+
+### aaaaa ###
+# aaa1
+# aaa2 #
+## aaa3
+### aaa4 ###
+## aaa##
+# aaa ##
+aaa5
+---
+
+
+>abc
+>def
+
+>abc
+>ghi
+
+>abc
+>jkl
+mno
+
+>abc *def*
+>ghi **jkl**
+>mno
+
+>abc
+>
+>    * def
+>    * ghi
+>
+>jkl
+
+aaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaa
+aaaaaaaaaaa
+> bbb
+
+cccccccccccccc
+cccccccccccccccc
+ccccccccccc
+
+>aaa
+>bbb
+
+<!-- >>ccc
+>>ddd 
+>eee -->
 
-<h1>aaaaa</h1>
 あああ
\ No newline at end of file
index 98411e7..fac71b7 100644 (file)
@@ -19,21 +19,48 @@ class BQParser {
        private val log:Log = LogFactory.getLog(classOf[BQParser])
 
        private val Syntax = LinkedHashMap(
-       "^(.*?)((\\s+\\d+?\\.\\s.+?\\\\,\\s*?)+)\\\\,\\s*?(.*?)$$" -> ("ol",surroundByListTAG _),
-       "^(.*?)((\\s+[\\*|\\+|\\-]\\s.+?\\\\,\\s*?)+)\\\\,\\s*?(.*?)$$" -> ("ul",surroundByListTAG _),
-       "^(.*?)\\*(.+?)\\*(.*?)$$" -> ("i",surroundByGeneralTAG _),
+       "^(.*?\\\\,)((>.*?\\\\,)+?)\\\\,(.*?)$$" -> ("blockquote",surroundByBlockquoteTAG _),
+       "^(.*?\\\\,)>(.*?)\\\\,\\\\,(.*?)$$" -> ("blockquote",surroundByGeneralTAG _),
+       "^(.*?)((\\s+\\d+?\\.\\s.+?\\\\,\\s*?)+?)(.*?)$$" -> ("ol",surroundByListTAG _),
+       "^(.*?)((\\s+(?:\\*|\\+|\\-)\\s.+?\\\\,\\s*?)+?)(.*?)$$" -> ("ul",surroundByListTAG _),
        "^(.*?)\\*\\*(.+?)\\*\\*(.*?)$$" -> ("em",surroundByGeneralTAG _),
-       "^(.*?)(#+)\\s(.+?)\\\\,(.*?)$$" -> ("h",surroundByHeadTAG _)
+       "^(.*?)\\*(.+?)\\*(.*?)$$" -> ("i",surroundByGeneralTAG _),
+       "^(.*\\\\,)(.*?)\\\\,(\\-+|=+)\\s*\\\\,(.*)$$" -> ("h",surroundByHeadTAGUnderlineStyle _),
+       "^(.*?)(#{1,6})\\s(.+?)(\\s#{1,6}?){0,1}\\\\,(.*?)$$" -> ("h",surroundByHeadTAG _)
        //"^(.*?)(\\\\,.+?\\\\,)(.*?)$$" -> ("p",surroundByAbstructTAG _)
        )
+       
+       private def surroundByBlockquoteTAG(doc:String, regex:String, TAG:String):String = {
+         val p = new Regex(regex, "before","inTAG","midInTag","following")
+         val m = p findFirstMatchIn(doc)
+         
+         var bef = ""
+         var fol = ""
+         var contentStr = ""
+         if(m != None){
+           val mid = m.get.group("inTAG")
+           log info "***-->" + mid
 
-/*     private def ulStyles(index:Int):String =  {
-
-    }
+           if(m.get.group("before") != None){bef = m.get.group("before")}else{bef = ""}
+               if(m.get.group("following") != None){fol = m.get.group("following")}else{fol = ""}
+               
+               log info "=>" + mid
+               if(mid != ""){
+                 val mat = """(>(.+?\\,))+?""".r.findAllMatchIn(mid)
+                 
+                 for(mt <- mat){
+                   contentStr += mt.group(2)
+                   log info "^^^" + mt
+                 }
+               }
 
-       private def olStyles(index:Int):String = 
+               log info "-->" + contentStr
+               return surroundByBlockquoteTAG(bef, regex, TAG) + 
+                               "<blockquote>" + contentStr + "</blockquote>" + surroundByBlockquoteTAG(fol, regex, TAG)
+         }
+         doc
        }
-*/
+
        private def surroundByListTAG(doc:String, regex:String, TAG:String):String = {
                val p = new Regex(regex, "before","elements","element","following")
                val m = p findFirstMatchIn(doc)
@@ -96,7 +123,7 @@ class BQParser {
                                                                        var i = indent
                        var list = List.empty[Tuple3[String,Int,String]]
                        for(elem <- doc){
-                         val m = s"""((\\s+?)$sign\\s(.+?)\\\\,)""".r.findFirstMatchIn(elem)
+                         val m = s"""((\\s+?)$sign\\s(.+?)\\,)""".r.findFirstMatchIn(elem)
                          list = (m.get.group(1),m.get.group(2).size,m.get.group(3))::list
                        }
 
@@ -124,34 +151,86 @@ class BQParser {
                tree.add(new TreeNode(s"</$sp>"*((i - indent)/indentWidth + 1)))
                return tree
          }
-               val r = s"""^(\\s*)${sign}.*?$$""".r("firstSpace")
-               val wS = r.findFirstMatchIn(s)
+               val r1 = s"""(\\s*)${sign}.*?\\,""".r
+               val wS1 = r1.findFirstMatchIn(s)
                var str = ""
-                
+               val r2 = s"""(\\s*)${sign}.*(\\\\,<br />.*?</blockquote>\\\\,)""".r
+               val wS2 = r2.findFirstMatchIn(s)
+               log debug "===>" + s
+               
+               var wS:Option[Regex.Match] = null
+               if(wS2 != None){wS = wS2}else if(wS1 != None){wS = wS1}
                if(wS != None){
-                       for(e <- _surroundByListTAG(docList.reverse,"li",wS.get.group("firstSpace").size)){
+                       for(e <- _surroundByListTAG(docList.reverse,"li",wS.get.group(1).size)){
                          str += e.toString()
-               }
+                       }
+                 if(wS == wS2){str += wS.get.group(2)}
+                 
+                 log debug "---->" + str
                  surroundByListTAG(bef,regex,TAG) + str + surroundByListTAG(fol,regex,TAG)
                }else{doc}
        }
        
+       private def surroundByHeadTAGUnderlineStyle(doc:String, regex:String, TAG:String):String = {
+         if(doc == ""){return doc}
+         
+         log debug "-->" + doc
+         val p = new Regex(regex, "before","inTAG","style","following")
+         val m = p findFirstMatchIn(doc)
+         var bef = ""
+         var fol = ""
+         var contentStr = ""
+         var headSign = TAG
+         if(m != None){
+           if(m.get.group("before") != None){bef = m.get.group("before")}else{bef = ""}
+           if(m.get.group("following") != None){fol = m.get.group("following")}else{fol = ""}
+           contentStr = m.get.group("inTAG")
+         
+           if(m.get.group("style").contains("-")){
+             headSign += "2"
+           }else{
+             headSign += "1"
+           }
+         
+           return surroundByHeadTAGUnderlineStyle(bef, regex, TAG) +
+                         s"<$headSign>$contentStr</$headSign>\\," + surroundByHeadTAGUnderlineStyle(fol, regex, TAG)
+         }
+         doc
+       }
+       
        private def surroundByHeadTAG(doc:String, regex:String, TAG:String):String = {
                if(doc == ""){return doc}
                
                log debug "--> " + doc
-               val p = new Regex(regex, "before","headSize","inTAG","following")
+               val p = new Regex(regex, "before","startHead","inTAG","endHead","following")
                val m = p findFirstMatchIn(doc)
+               var contentStr = ""
                if(m != None){
              var bef = ""
              var fol = ""
-
+             
                  if(m.get.group("before") != None){bef = m.get.group("before")}else{bef = ""}
              if(m.get.group("following") != None){fol = m.get.group("following")}else{fol = ""}
-                 val headSize = m.get.group("headSize").size
+             contentStr = m.get.group("inTAG")
+             
+                 val headSize = m.get.group("startHead").size
+                 val endHead = m.get.group("endHead")
+                 log debug "-->" + endHead
                  val headTAG = TAG + headSize
+                 if(endHead != null){
+                   val m2 = """^\s(#+?)$$""".r("wantSize").findFirstMatchIn(endHead)
+                   if(m2 != None){
+                     val size = m2.get.group("wantSize")
+                     if(size.size != headSize){
+                       contentStr += " " + size
+                       log warn "Curious header expression was found. " + 
+                       s" BlackQuill represents this <$headTAG>$contentStr</$headTAG> ."
+                     }
+                   }
+                 }
+                 
                  return surroundByHeadTAG(bef,regex,TAG) +
-                                 s"<${headTAG}>" + m.get.group("inTAG") + s"</${headTAG}>\\," +
+                                 s"<${headTAG}>$contentStr</${headTAG}>\\," +
                                  surroundByHeadTAG(fol,regex,TAG)
                }
          doc
index 3bfd71b..aa24375 100644 (file)
@@ -94,13 +94,13 @@ class HTMLMap{
 )
 
   private val specialChar = LinkedHashMap(
-    """\-\-""".r -> "&mdash;","""<=""".r -> "&hArr;","""<\->""".r -> "&harr;","""\->""".r ->"&rarr;","""<\-""".r ->"&larr;",
-    """=>""".r -> "&rArr;","""<=""".r -> "&lArr;","""\|\|^""".r -> "&uArr;",
-    """\|\|/""".r -> "&dArr;","""\|/""".r -> "&darr;","""\|^""".r -> "&uarr;","""\+\_""".r -> "&plusmn;","""!=""".r -> "&ne;",
+    """[^\-]\-\-[^\-+]""".r -> "&mdash;","""<=""".r -> "&hArr;","""<\->""".r -> "&harr;","""\->""".r ->"&rarr;","""<\-""".r ->"&larr;",
+    """=>""".r -> "&rArr;","""<=""".r -> "&lArr;","""\|\|\^""".r -> "&uArr;",
+    """\|\|/""".r -> "&dArr;","""\|/""".r -> "&darr;","""\|\^""".r -> "&uarr;","""\+\_""".r -> "&plusmn;","""!=""".r -> "&ne;",
     """~=""".r -> "&cong;","""<\_""".r -> "&le;",""">\_""".r -> "&ge","""\|FA""".r -> "&forall;","""\|EX""".r -> "&exist;",
     """\|=""".r -> "&equiv;","""\(\+\)""".r -> "&oplus;","""\(\-\)""".r -> "&ominus;","""\(X\)""".r -> "&otimes;",
     """\(c\)""".r -> "&copy;","""\(R\)""".r ->"&reg;","""\(SS\)""".r -> "&sect;","""\(TM\)""".r -> "&trade;",
-    """!in""".r -> "&notin;", """<""".r->"&lt;",""">""".r->"&gt;")
+    """!in""".r -> "&notin;", """<""".r->"&lt;","""[^\\,|^>+]>""".r->"&gt;")
 
   private def passThrough(text:String):String = {text}
   private def specialCharConvert(text:String):String = {