OSDN Git Service

implemented code TAG '
authorSet <set.minami@gmail.com>
Sat, 15 Jun 2013 08:23:58 +0000 (17:23 +0900)
committerSet <set.minami@gmail.com>
Sat, 15 Jun 2013 08:23:58 +0000 (17:23 +0900)
.cache
mdTest/test10.bq [new file with mode: 0644]
mdTest/test10.md [new file with mode: 0644]
mdTest/test11.bq [new file with mode: 0644]
mdTest/test7.bq [new file with mode: 0644]
mdTest/test8.bq [new file with mode: 0644]
mdTest/test9.bq [new file with mode: 0644]
src/main/scala/org/blackquill/engine/BQParser.scala
src/main/scala/org/blackquill/engine/HTMLMap.scala

diff --git a/.cache b/.cache
index e4f4b76..e419f61 100644 (file)
Binary files a/.cache and b/.cache differ
diff --git a/mdTest/test10.bq b/mdTest/test10.bq
new file mode 100644 (file)
index 0000000..fb23746
--- /dev/null
@@ -0,0 +1,9 @@
+
+foo
+---
+
+- - - 
+-------
+
+***
+* * * 
diff --git a/mdTest/test10.md b/mdTest/test10.md
new file mode 100644 (file)
index 0000000..b73ee15
--- /dev/null
@@ -0,0 +1,6 @@
+
+foo
+---
+
+- - - 
+-------
\ No newline at end of file
diff --git a/mdTest/test11.bq b/mdTest/test11.bq
new file mode 100644 (file)
index 0000000..9f50a12
--- /dev/null
@@ -0,0 +1,26 @@
+
+aaaaa
+[hoge](http://hoge.com/)
+[hoge](http://hoge.com "Title!")
+bbb
+
+aa`aaaabbb`ddddd
+``aaa`bbb``ccc
+``aaa`bbb`ccc``
+`````
+````
+``
+[1]:http://aaa.com
+[2]:http://bbb.com "TITLE"
+[3]:http://ccc.com
+
+ddd[aaa][2]
+eee
+[Google][]
+
+[4]:http://aaa.com
+[5]:http://bbb.com "TITLE"
+[6]:http://ccc.com
+[google]:http://www.google.com
+
+fff
\ No newline at end of file
diff --git a/mdTest/test7.bq b/mdTest/test7.bq
new file mode 100644 (file)
index 0000000..02953e7
--- /dev/null
@@ -0,0 +1,21 @@
+abc
+    aaaa
+def
+
+abc
+       aaaa
+def
+
+abc
+    aaa
+    bbb
+def
+
+abc
+       aaa
+       bbb
+def
+<h1>aaa</h1>
+    <h12345>aaa</h1>
+    &amp;
+ghi
\ No newline at end of file
diff --git a/mdTest/test8.bq b/mdTest/test8.bq
new file mode 100644 (file)
index 0000000..b732b23
--- /dev/null
@@ -0,0 +1,8 @@
+aaaa
+>111
+>>222
+>>>33<h1>44</h1>
+bbbbbbb&lt;bbbbbbbbb
+    <h1>aaa</h1>
+    &&aaaa
+aaaaaaaaa&gt;aaaaaaa
\ No newline at end of file
diff --git a/mdTest/test9.bq b/mdTest/test9.bq
new file mode 100644 (file)
index 0000000..d88a315
--- /dev/null
@@ -0,0 +1,4 @@
+abc
+    <h1>
+    &amp;
+def
\ No newline at end of file
index ffe1010..5a3afe8 100644 (file)
@@ -7,6 +7,7 @@ package org.blackquill.engine
 import org.apache.commons.logging._
 import scala.collection.immutable.List
 import scala.collection.mutable.LinkedHashMap
+import scala.collection.mutable.HashMap
 import scala.collection.mutable.Stack
 import scala.collection.mutable.ListMap
 import scala.collection.SortedSet
@@ -15,44 +16,229 @@ import scala.xml._
 
 import org.blackquill.engine._
 
+
 class BQParser {
        private val log:Log = LogFactory.getLog(classOf[BQParser])
 
+       private var urlDefMap = new HashMap[String,Tuple2[String,String]]
+
        private val Syntax = LinkedHashMap(
+       //STRONG
+       "^(.*?)`(.*)" -> ("code",surroundByCodeTAG _),
+       "^(.*)\\[(.+?)\\]\\[(.*?)\\](.*)$$" -> ("a",expandUrlDefinitions _),
+       "^(.*?)\\[(.*?)\\]\\((.+?)(\\x20+?\"(.+?)\")??\\)(.*?)$$" -> ("a", surroundaHrefTAG _),
+       "^(.*?\\\\,)(((?:\\x20{4,}|\\t+)(.*?\\\\,))+)(.*?)$$" -> ("code",surroundByPreCodeTAG _),
        "^(.*?\\\\,)((>.*(?:\\\\,))+?)(.*?)$$" -> ("blockquote",surroundByBlockquoteTAG _),
-       "^(.*?)((\\s+\\d+?\\.\\s.+?\\\\,)+)(.*?)$$" -> ("ol",surroundByListTAG _),
-       "^(.*?)((\\s+(?:\\*|\\+|\\-)\\s.+?\\\\,)+)(.*?)$$" -> ("ul",surroundByListTAG _),
+       "^(.*?)(((?:\\x20{4,}|\\t+)\\d+?\\.\\x20.+?\\\\,)+)(.*?)$$" -> ("ol",surroundByListTAG _),
+       "^(.*?)(((?:\\x20{4,}|\\t+)(?:\\*|\\+|\\-)\\x20.+?\\\\,)+)(.*?)$$" -> ("ul",surroundByListTAG _),
+       "^(.*?)(#{1,6})\\x20(.+?)(\\x20#{1,6}?)??\\\\,(.*?)$$" -> ("h",surroundByHeadTAG _),
+       "^(.*\\\\,)(.*?)\\\\,(\\-+|=+)\\x20*\\\\,(.*?)$$" -> ("h",surroundByHeadTAGUnderlineStyle _),
+       "^(.*\\\\,)((?:\\-|\\*){3,}|(?:(?:\\-|\\*)\\x20){3,})(.*?)$$" -> ("hr",putHrTAG _),
        "^(.*?)\\*\\*(.+?)\\*\\*(.*?)$$" -> ("strong",surroundByGeneralTAG _),
-       "^(.*?)\\*(.+?)\\*(.*?)$$" -> ("em",surroundByGeneralTAG _),
-       "^(.*?)(#{1,6})\\s(.+?)(\\s#{1,6}?)??\\\\,(.*?)$$" -> ("h",surroundByHeadTAG _),
-       "^(.*\\\\,)(.*?)\\\\,(\\-+|=+)\\s*\\\\,(.*)$$" -> ("h",surroundByHeadTAGUnderlineStyle _)
+       "^(.*?)\\*(.+?)\\*(.*?)$$" -> ("em",surroundByGeneralTAG _)
+       //WEAK
        //"^(.*?)(\\\\,.+?\\\\,)(.*?)$$" -> ("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)
-               }
+
+
+       private def surroundByCodeTAG(doc:String, regex:String, TAG:String):String = {
+           def _surroundByCodeTAG(doc:String,regex:String,innerSign:String,TAG:String):String = {
+               if(doc.contains(innerSign)){
+                       val p = regex.r
+                       val m = p.findFirstMatchIn(doc)
+
+                       if(m != None){
+                               val bef = m.get.group(1)
+                               var fol = m.get.group(2)
+                               var sign = "`"
+                               log debug "=>" + fol.head + " " + fol
+                               var follow = ""
+                               if((fol.head.toString == sign)&&(sign != "``")){
+                                       sign = "``"
+                                       follow = fol.tail
+                               }else{
+                                       follow = fol
+                               }
+                               log debug "**>" + follow
+                               log debug "==>" + sign
+                               val p2 = s"""^([^(?:\\,)]+?)$sign(.*)$$""".r
+                               val m2 = p2.findFirstMatchIn(follow)
+
+                               if(m2 != None){
+                                       log debug ">>>>" + m2.get.group(1)
+                                       return _surroundByCodeTAG(bef, regex, "`", TAG) + s"<$TAG>" + m2.get.group(1) + s"</$TAG>" +
+                                               _surroundByCodeTAG(m2.get.group(2), regex, "`", TAG)
+                               }else{
+                                       if(fol.startsWith("```")){
+                                               return _surroundByCodeTAG(bef, regex, "`", TAG) + s"<$TAG></$TAG>" +
+                                                       _surroundByCodeTAG(follow.drop(2), regex, "`", TAG)
+                                       }else if(fol.startsWith("`")){
+                                               return _surroundByCodeTAG(bef, regex, "`", TAG) + s"<$TAG></$TAG>" +
+                                                       _surroundByCodeTAG(follow.drop(0), regex, "`", TAG)
+                                       }else{
+                                                       log warn s"$sign CodeBlock is wrong."
+                                               return ""
+                                       }
+                               }
+                       }else{return doc}
+               }else{return doc}
            }
-         }
-         text
+    _surroundByCodeTAG(doc,regex,"`",TAG)
+       }
+
+       private def expandUrlDefinitions(doc:String, regex:String, TAG:String):String = {
+               val m = regex.r.findFirstMatchIn(doc)
+               if(m != None){
+                       var key = ""
+                       if(m.get.group(3) != ""){
+                         key = m.get.group(3)
+                       }else{
+                         key = m.get.group(2).toLowerCase()
+                       }
+
+                       if(urlDefMap.contains(key)){
+                               return expandUrlDefinitions(m.get.group(1), regex, TAG) +
+                                               s"""<$TAG href=\"${urlDefMap(key)._1}\" title=\"${urlDefMap(key)._2}\">""" +
+                                               m.get.group(2) + s"""</$TAG>""" + expandUrlDefinitions(m.get.group(4), regex, TAG)
+                       }else{
+                         log warn "Link definition was not found : " + key
+                         doc
+                       }
+               }else{
+                 doc
+               }
+
+       }
+
+       private def urlDefinitions(doc:String):String = {
+               def _urlDefinitions(text:String):String = {
+                   var bef = ""
+                   var fol = ""
+
+                   log debug "doc ==>" + text
+                   val p = new Regex("""^(.*?){0,1}(((\[([\w\d\.\,\-]+?)\]:([\w\d:\/\.]+?)(\s+\"(.+?)\"){0,1})\\,)+?)(?:\\,|\z)(.*){0,1}$$""",
+                               "before","seq","elem1","elem2","landMark","link","test","Title", "following")
+                   val m = p findFirstMatchIn(text)
+                       if(text == ""){return text}
+                       if(m != None){
+                               if(m.get.group("before") != None){bef = m.get.group("before")}
+                               if(m.get.group("following") != None){fol = m.get.group("following")}
+
+                               log debug "bef=>" + bef
+                               log debug "seq=>" + m.get.group("seq")
+                               log debug "fol=>" + fol
+                               if(m.get.group("seq") != None){
+                                       val seq = m.get.group("seq")
+                                       val mat = """\[(.+?)\]:([\w\d:\/\.]+)(\s+\"(.+)\"){0,1}(?:\\,){0,1}""".r.findAllMatchIn(seq)
+                                       for(e <- mat){
+                                               val link = e.group(2)
+                                               log debug ">>" + link
+                                               val landMark = e.group(1)
+                                               log debug ">>>" + landMark
+                                               var title = ""
+                                               if(e.group(4) != null){title = e.group(4)}
+
+                                               urlDefMap += (landMark.toLowerCase->(link,title))
+                                       }
+                               }
+                               _urlDefinitions(bef) + _urlDefinitions(fol)
+                       }else{
+                         log debug "m was None!"
+                         text}
+
+               }
+               _urlDefinitions(doc)
+       }
+
+       private def surroundaHrefTAG(doc:String,regex:String,TAG:String):String = {
+               val p = new Regex(regex,"before","inTag","link","ab","title","following")
+               val m = p findFirstMatchIn(doc)
+
+               var bef = ""
+               var fol = ""
+               if(m != None){
+                       if(m.get.group("before") != None){
+                         bef = m.get.group("before")
+                       }
+                       if(m.get.group("following") != None){fol = m.get.group("following")}
+
+                       val link = m.get.group("link")
+                       val label = m.get.group("inTag")
+                       if(m.get.group("title") == null){
+                               return surroundaHrefTAG(bef,regex,TAG) + s"""<$TAG href=\"$link\">$label</$TAG>""" +
+                                               surroundaHrefTAG(fol,regex,TAG)
+                       }else{
+                               val title = m.get.group("title")
+                               return surroundaHrefTAG(bef, regex, TAG) +
+                                               s"""<$TAG href=\"$link\" title=\"$title\">$label</$TAG>""" +
+                                               surroundaHrefTAG(fol,regex,TAG)
+                       }
+               }
+               doc
+       }
+
+       private def putHrTAG(doc:String, regex:String, TAG:String):String = {
+               val p = new Regex(regex,"before","line","following")
+               val m = p findFirstMatchIn(doc)
+
+               log debug doc
+
+               var bef = ""
+               var fol = ""
+               if(m != None){
+                       if(m.get.group("before") != None){
+                       bef = m.get.group("before")
+                       }
+                       if(m.get.group("following") != None){fol = m.get.group("following")}
+
+                       return putHrTAG(bef,regex,TAG) + s"<$TAG />" + putHrTAG(fol,regex,TAG)
+               }
+         doc
+       }
+
+       private def surroundByPreCodeTAG(doc:String, regex:String, TAG:String):String = {
+               val p = new Regex(regex, "before","seq","inTAG","midInTag","following")
+               val m = p findFirstMatchIn(doc)
+               log debug "[" + doc + "]"
+
+               var bef = ""
+               var fol = ""
+               var contentStr = ""
+               if(m != None){
+                 if(m.get.group("before") != None){
+                   bef = m.get.group("before")
+                 }
+                 if(m.get.group("following") != None){fol = m.get.group("following")}
+
+                 log debug "^^^" + m.get.group("seq")
+                 val mat = """((?:\x20{4,}|\t+)(.*?\\,))+?""".r.findAllMatchIn(m.get.group("seq"))
+                 for(elem <- mat){
+                   contentStr += elem.group(2)
+                   log debug "***" + contentStr
+                 }
+
+                 log debug contentStr
+                 return surroundByPreCodeTAG(bef,regex,TAG) +
+                                 s"<pre><$TAG>" +
+                                 contentStr.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;") +
+                                 s"</$TAG></pre>\\," +
+                                 surroundByPreCodeTAG(fol, regex, TAG)
+               }
+
+         doc
        }
+
        private def surroundByBlockquoteTAG(doc:String, regex:String, TAG:String):String = {
          val p = new Regex(regex, "before","inTAG","midInTag","following")
          val m = p findFirstMatchIn(doc)
-         log info "[" + doc + "]"
-               
+         log debug "[" + doc + "]"
+
          var bef = ""
          var fol = ""
          var contentStr = ""
          if(m != None){
            var mid = m.get.group("inTAG")
-           log info "***-->" + mid
+           log debug "***-->" + mid
 
            if(m.get.group("before") != None){
              bef = m.get.group("before")
@@ -62,13 +248,13 @@ class BQParser {
              }
            }else{bef = ""}
                if(m.get.group("following") != None){fol = m.get.group("following")}else{fol = ""}
-               
-               log info "=>" + mid
+
+               log debug "=>" + 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
@@ -79,17 +265,17 @@ class BQParser {
                      if(m == None){break = "<br />\\\\,"}
                      contentStr += mt.group(1).tail.replaceAll("\\\\,", break)
                    }else{
-                     log info "(" + mt.group(1) + ")"
+                     log debug "(" + mt.group(1) + ")"
                      following += mt.group(1)
-                   }               
-                   log info "^^^" + mt
+                   }
+                   log debug "^^^" + mt
                  }
                }
-               
+
                following += fol
-               log info "bef=" + bef + " mid=" + contentStr + " fol="  + following 
-               log info "-->" + contentStr
-               return surroundByBlockquoteTAG(bef, regex, TAG) + 
+               log debug "bef=" + bef + " mid=" + contentStr + " fol="  + following
+               log debug "-->" + contentStr
+               return surroundByBlockquoteTAG(bef, regex, TAG) +
                                s"<$TAG>\\," + surroundByBlockquoteTAG(contentStr, regex, TAG) + s"</$TAG>\\," +
                                surroundByBlockquoteTAG(following, regex, TAG)
          }
@@ -111,12 +297,12 @@ class BQParser {
                  return doc
                }
 
-               
+
                var sign = ""
                var sp = ""
                val indentWidth = 4
                var styles:((Int) => String) = null
-               
+
                TAG match{
              case "ul"=>
                sp = TAG
@@ -136,50 +322,50 @@ class BQParser {
                            case 1 => "decimal"
                            case 2 => "decimal-leading-zero"
                            case 3 => "upper-latin"
-                           case 0 => "lower-latin"                         
+                           case 0 => "lower-latin"
                            case _ => "---"
                          }
                }
                sign = "\\d+?\\."
            }
-               
+
                log debug ":::" + s
                var docList = List[String]()
-               for(elem <- s"""(\\s+?$sign\\s.+?\\\\,)+?""".r.findAllMatchIn(s)){                               
+               for(elem <- s"""(\\x20+?$sign\\x20.+?\\\\,)+?""".r.findAllMatchIn(s)){
                        docList = elem.group(1)::docList
                }
 
 
-               
-               def _surroundByListTAG(doc:List[String],TAG:String,indent:Int):TreeNode[String] = {     
+
+               def _surroundByListTAG(doc:List[String],TAG:String,indent:Int):TreeNode[String] = {
                        var tree = new TreeNode[String]("")
-                   if(doc.isEmpty){return tree}                                                
-                       
+                   if(doc.isEmpty){return tree}
+
                        log debug "====>" + doc
                        tree.add(new TreeNode("<" + sp + s""" style=\"list-style-type:${styles(indent)}\">"""))
                        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"""((\\x20+?)$sign\\x20(.+?)\\\\,)""".r.findFirstMatchIn(elem)
                          list = (m.get.group(1),m.get.group(2).size,m.get.group(3))::list
                        }
 
                        var restStr = List[String]()
                        if(list.isEmpty){return new TreeNode("")
                        }else{for(e <- list.reverse.tail){restStr = e._1::restStr}}
-                       
+
                        restStr = restStr.reverse
-                       for(elem <- list.reverse){                      
-                               if(elem._2 > i){                           
+                       for(elem <- list.reverse){
+                               if(elem._2 > i){
                                        tree.add(new TreeNode("<" + sp + s""" style=\"list-style-type:${styles(elem._2)}\">"""))
-                               }else if(elem._2 < i){                                  
+                               }else if(elem._2 < i){
                                        tree.add(new TreeNode[String](s"</$sp>"*((i - elem._2)/indentWidth)))
                                }
-                               tree.add(new TreeNode[String](s"<$TAG>" + elem._3 + s"</$TAG>\\,"))     
-                               
-                               
+                               tree.add(new TreeNode[String](s"<$TAG>" + elem._3 + s"</$TAG>\\,"))
+
+
                                if(restStr.isEmpty){
-                                       restStr = List[String]("")                                
+                                       restStr = List[String]("")
                                }else{
                                        restStr = restStr.tail
                                }
@@ -188,14 +374,14 @@ class BQParser {
                tree.add(new TreeNode(s"</$sp>"*((i - indent)/indentWidth + 1)))
                return tree
          }
-               
+
                log debug "->" + docList
-               val r1 = s"""(\\s*)${sign}.*?\\\\,""".r
+               val r1 = s"""(\\x20*)${sign}.*?\\\\,""".r
                val wS1 = r1.findFirstMatchIn(s)
                var str = ""
-               val r2 = s"""(\\s*)${sign}.*(\\\\,<br />.*?</blockquote>\\\\,)""".r
+               val r2 = s"""(\\x20*)${sign}.*(\\\\,<br />.*?</blockquote>\\\\,)""".r
                val wS2 = r2.findFirstMatchIn(s)
-               
+
                var wS:Option[Regex.Match] = null
                if(wS2 != None){wS = wS2}else if(wS1 != None){wS = wS1}
                if(wS != None){
@@ -203,15 +389,15 @@ class BQParser {
                          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)
@@ -223,22 +409,22 @@ class BQParser {
            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","startHead","inTAG","endHead","following")
                val m = p findFirstMatchIn(doc)
@@ -246,34 +432,34 @@ class BQParser {
                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 = ""}
              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)
+                   val m2 = """^\x20(#+?)$$""".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. " + 
+                       log warn "Curious header expression was found. " +
                        s" BlackQuill represents this <$headTAG>$contentStr</$headTAG> ."
                      }
                    }
                  }
-                 
+
                  return surroundByHeadTAG(bef,regex,TAG) +
                                  s"<${headTAG}>$contentStr</${headTAG}>\\," +
                                  surroundByHeadTAG(fol,regex,TAG)
                }
          doc
        }
-       
+
        private def surroundByGeneralTAG(doc:String, regex:String, TAG:String):String = {
          if(doc == ""){return doc}
          log debug doc
@@ -284,36 +470,43 @@ class BQParser {
              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 = ""}
-                 return surroundByGeneralTAG(bef,regex,TAG) + 
+                 return surroundByGeneralTAG(bef,regex,TAG) +
                                  s"<${TAG}>" + m.get.group("inTAG") + s"</${TAG}>" +
                          surroundByGeneralTAG(fol,regex,TAG)
          }
          doc
        }
-       
+
        private def constructHEADER(doc:String):String = {
          val headTAG = "head"
          val titleTAG = "title"
          var title = "NO TITLE"
-         
-         val p = new Regex("""(?i)#{1,6}\s(.+?)\\,""")
+
+         val p = new Regex("""(?i)#{1,6}\x20(.+?)\\,""")
          val m = p findFirstMatchIn(doc)
          if(m != None){title = m.get.group(1)}
-         
+
          s"<${headTAG}>\n<${titleTAG}>${title}</${titleTAG}>\n</${headTAG}>"
        }
-       
+
+       def preProcessors(doc:String) :String = {
+        val text = urlDefinitions(doc)
+        text
+       }
+
        def toHTML(markdown:String):String = {
                val docType = "<!DOCTYPE html>"
                val bodyTAG = "body"
                val htmlTAG = "html"
-               var md = markdown
+               var md = preProcessors(markdown + "\\,")
+
                for(k <- Syntax keys){
                 md = Syntax(k)._2(md, k, Syntax(k)._1)
                }
+               log debug urlDefMap
                val header = constructHEADER(markdown)
-               s"${docType}\n${header}\n<${htmlTAG}>\n<${bodyTAG}>\n${layoutControl(md, specialLayout).replaceAll("\\\\,","\n")}\n</${bodyTAG}>\n</${htmlTAG}>"
+               s"${docType}\n${header}\n<${htmlTAG}>\n<${bodyTAG}>\n${md.replaceAll("\\\\,","\n")}\n</${bodyTAG}>\n</${htmlTAG}>"
        }
-       
-       
+
+
 }
\ No newline at end of file
index aa24375..eb312ea 100644 (file)
@@ -100,18 +100,69 @@ class HTMLMap{
     """~=""".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;","""\\&""".r->"&amp;")
 
+  
   private def passThrough(text:String):String = {text}
-  private def specialCharConvert(text:String):String = {
+  
+  def specialCharConvert(text:String):String = {
     var str = text
     for(elem <- specialChar.keys){
       str = elem replaceAllIn(str,m => specialChar(elem))
     }
     str
   }
+  
+/*
+  def ampConverter(text:String):String = {
+    val index = text.indexWhere(_ == '&',0)
+    
+    val headStr = text.slice(0,index)
+    val subStr = text.slice(index,text.size)
+    
+    val amp : Regex = """^(.*?)(&(.+?)(;|\\,))(.*?)$$""".r
+    subStr match{
+      case amp(v1,v2,v3,v4,v5) =>
+        if("\\,".equals(v4)){
+          return headStr + (v1 + v2).replaceAll("&","&amp;") + ampConverter(v5)
+        }else if(";".equals(v4)){
+          return headStr + v1.replaceAll("&","&amp;") + v2 + ampConverter(v5)      
+        }
+      case _ => return text
+    }
+    text
+  }
+  
+  def gtConverter(text:String):String = {
+   if(text.contains(">")){
+     val index = text.indexWhere(_ == '>',0)
+     if(index < 2){return text}
+     
+     val headStr = text.slice(0,index -2)     
+     val subStr = text.slice(index - 2,text.size)
 
-
+     val gtSeq : Regex = """(.*?)(>+)(.*?)""".r 
+     subStr match{    
+       case  gtSeq(v1,v2,v3) =>
+         log debug subStr
+         log debug v1
+         if(v1 == "\\,"){
+           log debug "***->" + v2
+           return headStr + v1 + v2 + gtConverter(v3)
+         }else{
+           return headStr + v1 + v2.replaceFirst(v2,"&gt;"*v2.size) + gtConverter(v3)
+         }
+       case _ =>
+         return headStr + subStr
+     }
+   }else{return text}
+ }
+  
+  def ltConverter(text:String):String ={
+       text.replaceAll("<","&lt;")
+  }
+ */
   def htmlTAGFilter(doc:String):String = {
     if(doc == ""){return ""}
     val node = new BQParser
@@ -155,7 +206,7 @@ class HTMLMap{
                                "before","attribute","inTAG","following")
                val m = p findFirstMatchIn(doc)
                if(m != None){
-                       log info "[" + elem + "]"
+                       log debug "[" + elem + "]"
                        return htmlTAGFilter(m.get.group("before")) + 
                                        "<" + elem + m.get.group("attribute") + ">" + 
                                        HTMLTag(elem)._2(m.get.group("inTAG")) + endTag + 
@@ -171,7 +222,8 @@ class HTMLMap{
        }
       }        
     }
-    specialCharConvert(doc):String
+    specialCharConvert(doc)
+    
   }
 
 }
\ No newline at end of file