OSDN Git Service

blockquote has implemented
authorSet <set.minami@gmail.com>
Mon, 3 Jun 2013 04:43:15 +0000 (13:43 +0900)
committerSet <set.minami@gmail.com>
Mon, 3 Jun 2013 04:43:15 +0000 (13:43 +0900)
.cache
mdTest/test5.bq
mdTest/test6 [new file with mode: 0644]
mdTest/test6.bq [new file with mode: 0644]
planAndproceed.png
src/main/scala/org/blackquill/engine/BQParser.scala
src/main/scala/org/blackquill/main/BlackQuill.scala

diff --git a/.cache b/.cache
index 4763e81..e4f4b76 100644 (file)
Binary files a/.cache and b/.cache differ
index e2a61a4..eff848f 100644 (file)
@@ -3,7 +3,11 @@ aaaaaaaa
 -=-=
 bbbbb<-testccccccc
 <hr><br><br>
-
+>1111
+>2222
+>>3333
+>>4444
+>5555
 # TITLE
 ### TITLE2
 <link href="test->test" />
@@ -93,8 +97,8 @@ cccccccccccccc
 cccccccccccccccc
 ccccccccccc
 >aaa
->bbb
->>ccc
+>>bbb
+>>>ccc
 >>ddd 
 >eee
 
diff --git a/mdTest/test6 b/mdTest/test6
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/mdTest/test6.bq b/mdTest/test6.bq
new file mode 100644 (file)
index 0000000..2c785bd
--- /dev/null
@@ -0,0 +1,20 @@
+aaa
+>aaa
+aaa
+>111
+>222
+aaa
+>111
+>>222
+>111
+aaa
+>>222
+>>222
+>111
+aaa
+>>222
+aaa
+>111
+>>222
+>>222
+aaa
\ No newline at end of file
index 2f4a8ad..782d547 100644 (file)
Binary files a/planAndproceed.png and b/planAndproceed.png differ
index e5e4976..ffe1010 100644 (file)
@@ -19,18 +19,29 @@ class BQParser {
        private val log:Log = LogFactory.getLog(classOf[BQParser])
 
        private val Syntax = LinkedHashMap(
-       //"^()((>.*?\\\\,)+?)\\\\,(.*?)$$" -> ("blockquote",surroundByBlockquoteTAG _),     
-       "^(.*?\\\\,)((>.*?\\\\,)+?)(\\\\,.*?)$$" -> ("blockquote",surroundByBlockquoteTAG _),
-       //"^(.*?\\\\,)>(.*?)\\\\,\\\\,(.*?)$$" -> ("blockquote",surroundByGeneralTAG _),
+       "^(.*?\\\\,)((>.*(?:\\\\,))+?)(.*?)$$" -> ("blockquote",surroundByBlockquoteTAG _),
        "^(.*?)((\\s+\\d+?\\.\\s.+?\\\\,)+)(.*?)$$" -> ("ol",surroundByListTAG _),
        "^(.*?)((\\s+(?:\\*|\\+|\\-)\\s.+?\\\\,)+)(.*?)$$" -> ("ul",surroundByListTAG _),
-       "^(.*?)\\*\\*(.+?)\\*\\*(.*?)$$" -> ("em",surroundByGeneralTAG _),
-       "^(.*?)\\*(.+?)\\*(.*?)$$" -> ("i",surroundByGeneralTAG _),
-       "^(.*\\\\,)(.*?)\\\\,(\\-+|=+)\\s*\\\\,(.*)$$" -> ("h",surroundByHeadTAGUnderlineStyle _),
-       "^(.*?)(#{1,6})\\s(.+?)(\\s#{1,6}?){0,1}\\\\,(.*?)$$" -> ("h",surroundByHeadTAG _)
+       "^(.*?)\\*\\*(.+?)\\*\\*(.*?)$$" -> ("strong",surroundByGeneralTAG _),
+       "^(.*?)\\*(.+?)\\*(.*?)$$" -> ("em",surroundByGeneralTAG _),
+       "^(.*?)(#{1,6})\\s(.+?)(\\s#{1,6}?)??\\\\,(.*?)$$" -> ("h",surroundByHeadTAG _),
+       "^(.*\\\\,)(.*?)\\\\,(\\-+|=+)\\s*\\\\,(.*)$$" -> ("h",surroundByHeadTAGUnderlineStyle _)
        //"^(.*?)(\\\\,.+?\\\\,)(.*?)$$" -> ("p",surroundByAbstructTAG _)
        )
        
+       private val specialLayout:List[String] = List("blockquote")
+       private def layoutControl(text:String,tags:List[String]):String = {
+         for(l <- tags.iterator){
+           val m = s"""^(.*?)<$l>((.*?\\,)+?)</$l>(.*?)$$""".r.findAllMatchIn(text)
+           if(m != null){
+               for(e <- m){
+                       e.group(3).replaceAll("\\,", "<br />\\,")
+                       log info e.group(3)
+               }
+           }
+         }
+         text
+       }
        private def surroundByBlockquoteTAG(doc:String, regex:String, TAG:String):String = {
          val p = new Regex(regex, "before","inTAG","midInTag","following")
          val m = p findFirstMatchIn(doc)
@@ -53,28 +64,34 @@ class BQParser {
                if(m.get.group("following") != None){fol = m.get.group("following")}else{fol = ""}
                
                log info "=>" + mid
+               var following = ""
                if(mid != null){
                  val mat = """(.+?\\,)+?""".r.findAllMatchIn(mid)
                  
-                 var inCurrentBQ = true
-                 
+                 var inCurrentBQ = true                  
                  for(mt <- mat){
                    if(!mt.group(1).startsWith(">")||mt.group(1) == "\\\\,"){
                        inCurrentBQ = false
                    }
                    if(inCurrentBQ){
-                     contentStr += mt.group(1).tail
+                     val m = """.*?<br />\\,$$""".r.findFirstMatchIn(mt.group(1))
+                     var break = "\\\\,"
+                     if(m == None){break = "<br />\\\\,"}
+                     contentStr += mt.group(1).tail.replaceAll("\\\\,", break)
                    }else{
                      log info "(" + mt.group(1) + ")"
-                     fol += mt.group(1)}                   
+                     following += mt.group(1)
+                   }               
                    log info "^^^" + mt
                  }
                }
-               log info "bef=" + bef + " mid=" + contentStr + " fol="  + fol 
+               
+               following += fol
+               log info "bef=" + bef + " mid=" + contentStr + " fol="  + following 
                log info "-->" + contentStr
                return surroundByBlockquoteTAG(bef, regex, TAG) + 
                                s"<$TAG>\\," + surroundByBlockquoteTAG(contentStr, regex, TAG) + s"</$TAG>\\," +
-                               surroundByBlockquoteTAG(fol, regex, TAG)
+                               surroundByBlockquoteTAG(following, regex, TAG)
          }
          doc
        }
@@ -143,7 +160,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
                        }
 
@@ -295,7 +312,7 @@ class BQParser {
                 md = Syntax(k)._2(md, k, Syntax(k)._1)
                }
                val header = constructHEADER(markdown)
-               s"${docType}\n${header}\n<${htmlTAG}>\n<${bodyTAG}>\n${md}\n</${bodyTAG}>\n</${htmlTAG}>"
+               s"${docType}\n${header}\n<${htmlTAG}>\n<${bodyTAG}>\n${layoutControl(md, specialLayout).replaceAll("\\\\,","\n")}\n</${bodyTAG}>\n</${htmlTAG}>"
        }
        
        
index 238e51a..004f828 100644 (file)
@@ -117,7 +117,7 @@ object BlackQuill{
     // - fileHandler.openMarkdownFromString(str:String)
     val text:List[String] = fileHandler openMarkdownFromFile(Switches.getInputfile)
     val output = blackquill(text)
-    log info output
+  //  log info output
   }
 
   def blackquill(lines:List[String]):List[String] = {