OSDN Git Service

speedup
authorSet <set.minami@gmail.com>
Wed, 7 Aug 2013 10:55:10 +0000 (19:55 +0900)
committerSet <set.minami@gmail.com>
Wed, 7 Aug 2013 10:55:10 +0000 (19:55 +0900)
build.pl
build.sbt
mdTest/test16.bq
mdTest/test16.html
src/main/scala/org/blackquill/engine/BQParser.scala
src/main/scala/org/blackquill/engine/HTMLMap.scala
src/main/scala/org/blackquill/main/BlackQuill.scala

index 4399372..5507146 100644 (file)
--- a/build.pl
+++ b/build.pl
@@ -38,6 +38,8 @@ if (-e $jarFile) {
        open my $cmd , '>', $commandFile||die "command file cannot be generated.";
        print $cmd @cmds;
        close $cmd;
+       my $result = chmod 0755 ,$commandFile;
+       if($result != 1){die "Cannot change permission."}
 }else{
        print "executable jar file not found." . "\n";
 }
index 4a0ae8e..6177f4a 100644 (file)
--- a/build.sbt
+++ b/build.sbt
@@ -9,7 +9,7 @@ import sbtassembly.Plugin._
 
 name := "BlackQuill"
 
-version := "0.1.0"
+version := "0.1.1"
 
 scalaVersion := "2.10.0"
 
index 39b50af..3c3a44c 100644 (file)
@@ -1,4 +1,10 @@
+<link href="../css/markdown.css" type="text/css" rel="stylesheet"/>
 {toc:h2-h6}
+
+# コーディングを支える技術
+西尾泰和
+$date
+
 {nrange:h2-h6}
 
 aaa
index cc5a3f8..052b0bd 100644 (file)
@@ -1,37 +1,27 @@
 <!DOCTYPE html>
 <head>
-<title>test1</title>
+<title>コーディングを支える技術</title>
 </head>
 <html>
 <body>
+<p><link href="../css/markdown.css" type="text/css" rel="stylesheet"></p>
 <header>
 <ul style="list-style:none" id="toc"><nav>
-<li><a href="#2:aaa:15" ><h2>aaa</h2></a></li>
-<ul style="list-style:none" >
-<li><a href="#3:test1:16" ><h3>test1</h3></a></li>
-<ul style="list-style:none" >
-<li><a href="#5:test3:19" ><h5>test3</h5></a></li>
-</ul>
-</ul>
-<li><a href="#2:test4:20" ><h2>test4</h2></a></li>
 <li><a href="#2:aaa:21" ><h2>aaa</h2></a></li>
-<li><a href="#foo" ><h2>aaa</h2></a></li>
-<li><a href="#2:1. &rarr; 1:28" ><h2>1. &rarr; 1</h2></a></li>
-<li><a href="#2:2. &rarr; 2:29" ><h2>2. &rarr; 2</h2></a></li>
 <ul style="list-style:none" >
-<li><a href="#3:2.1. &rarr; 2.1.:30" ><h3>2.1. &rarr; 2.1.</h3></a></li>
+<li><a href="#3:test1:22" ><h3>test1</h3></a></li>
 <ul style="list-style:none" >
-<li><a href="#4:2.1.1. &rarr; 2.1.1.:31" ><h4>2.1.1. &rarr; 2.1.1.</h4></a></li>
+<li><a href="#5:test3:25" ><h5>test3</h5></a></li>
 </ul>
 </ul>
-<li><a href="#3:2.2. &rarr; 2.2.:32" ><h3>2.2. &rarr; 2.2.</h3></a></li>
-<ul style="list-style:none" >
-<li><a href="#4:2.2.1. &rarr; 2.2.1:33" ><h4>2.2.1. &rarr; 2.2.1</h4></a></li>
-</ul>
-<li><a href="#3:2.3. &rarr; 2.3.:34" ><h3>2.3. &rarr; 2.3.</h3></a></li>
-<li><a href="#2:3. &rarr; 3.:35" ><h2>3. &rarr; 3.</h2></a></li>
+<li><a href="#2:test4:26" ><h2>test4</h2></a></li>
+<li><a href="#2:aaa:27" ><h2>aaa</h2></a></li>
+<li><a href="#foo" ><h2>aaa</h2></a></li>
 </nav></ul>
 </header>
+<h1 >コーディングを支える技術</h1>
+<p>西尾泰和</p>
+<p>$date</p>
 <dl>
 <dt>aaa</dt><dd>bbb</dd>
 <dt>ccc</dt><dd>dddddd</dd>
 
 </dl>
 <p><span style=" color:red; background-color:yellow;()">aaa</span> </p>
-<p><span style=" color:#00FF00; font-size:larger; font-weight:light font-family:'Times''suns';()">bbb</span> </p>
+<p><span style=" color:#00FF00; font-size:larger; font-weight:light font-family:'Times'</p>
+<p>'suns';()">bbb</span> </p>
 <p><span style=" color:#FFFFFF; background-color:#000000; font-size:larger; font-weight:bolder font-family:'Times';()">bbb</span> </p>
 <p><span style=" color:red; font-size:larger; font-weight:bolder font-family:'Times'; text-decoration:overline;">bbb</span> </p>
-<h2 id="2:aaa:15">aaa</h2>
-<h3 id="3:test1:16">test1</h3>
+<h2 id="2:aaa:21">aaa</h2>
+<h3 id="3:test1:22">test1</h3>
 <p>aaaaaaaa55555</p>
 <p>aaaa</p>
-<h5 id="5:test3:19">test3</h5>
-<h2 id="2:test4:20">test4</h2>
-<h2 id="2:aaa:21">aaa</h2>
+<h5 id="5:test3:25">test3</h5>
+<h2 id="2:test4:26">test4</h2>
+<h2 id="2:aaa:27">aaa</h2>
 <h2 id="foo">aaa</h2>
 <p>aaaaaaa <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>+</mo><mn>2</mn></mrow><annotation encoding="SnuggleTeX">$1+2 $</annotation></semantics></math> bbbbbbbb</p>
-<p><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>=</mo><mfrac><mrow><mi>?</mi><mo>+</mo><mi>?</mi></mrow><mrow><mi>?</mi><mo>+</mo><mi>?</mi></mrow></mfrac></mrow><annotation encoding="SnuggleTeX">$ A = \frac{\alpha + \beta}{\gamma + \delta} $</annotation></semantics></math></p>
+<p><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>=</mo><mfrac><mrow><mi>&alpha;</mi><mo>+</mo><mi>&beta;</mi></mrow><mrow><mi>&gamma;</mi><mo>+</mo><mi>&delta;</mi></mrow></mfrac></mrow><annotation encoding="SnuggleTeX">$ A = \frac{\alpha + \beta}{\gamma + \delta} $</annotation></semantics></math></p>
 <p>aaaaaaaaaaaaa</p>
-<h2 id="2:1. &rarr; 1:28">1. &rarr; 1</h2>
-<h2 id="2:2. &rarr; 2:29">2. &rarr; 2</h2>
-<h3 id="3:2.1. &rarr; 2.1.:30">2.1. &rarr; 2.1.</h3>
-<h4 id="4:2.1.1. &rarr; 2.1.1.:31">2.1.1. &rarr; 2.1.1.</h4>
-<h3 id="3:2.2. &rarr; 2.2.:32">2.2. &rarr; 2.2.</h3>
-<h4 id="4:2.2.1. &rarr; 2.2.1:33">2.2.1. &rarr; 2.2.1</h4>
-<h3 id="3:2.3. &rarr; 2.3.:34">2.3. &rarr; 2.3.</h3>
-<h2 id="2:3. &rarr; 3.:35">3. &rarr; 3.</h2>
-<div style="border:1px solid gray; width:300px;border-radius:10px;"> 
-aaaaaa
+<h2>1. &rarr; 1\</h2>
+<h2>2. &rarr; 2\</h2>
+<h3>2.1. &rarr; 2.1.\</h3>
+<h4>2.1.1. &rarr; 2.1.1.\</h4>
+<h3>2.2. &rarr; 2.2.\</h3>
+<h4>2.2.1. &rarr; 2.2.1\</h4>
+<h3>2.3. &rarr; 2.3.\</h3>
+<h2>3. &rarr; 3.\</h2>
+<p>|-:b=1 solid gray w=300 rad=10------------|</p>
+<p>aaaaaa</p>
 <h1 >qqqqqq</h1>
-<div style="border:2px solid gray; width:200px;border-radius:10px;"> 
-aaaaaa
-</div>
-<div style="border:3px solid gray; width:200px;border-radius:10px;"> 
-cccccc
-</div>
-</div>
+<p>|-:b=2 solid gray w=200 rad=10------------|</p>
+<p>aaaaaa</p>
+<p>|______|</p>
+<p>|-:b=3 solid gray w=200 rad=10------------|</p>
+<p>cccccc</p>
+<p>|______|</p>
+<p>|_________________________________________|</p>
 
 </body>
 </html>
\ No newline at end of file
index a5a248f..d4861c6 100644 (file)
@@ -29,6 +29,11 @@ import org.blackquill.main._
 import org.blackquill.io.FileIO
 import org.blackquill.breadboard.Latexconverter
 
+//import scala.actors.Actor._
+// import scala.concurrent._
+// import scala.concurrent.duration._
+// import ExecutionContext.Implicits.global
+// import scala.util.{Failure, Success}
 
 class BQParser {
        private val log:Log = LogFactory.getLog(classOf[BQParser])
@@ -43,44 +48,45 @@ class BQParser {
        private val texSignStart = """\\begin\{TeX\}"""
        private val texSignEnd = """\\end\{TeX\}"""
 
-       private val Syntax = LinkedHashMap(
+
+       val Syntax = LinkedHashMap[Regex,(String,(String,Regex,String)=>String)](
        //Early
-       """^(.*\\,)\|\-:b\s*=\s*(\d+?)\s+(\w+?)\s+(#?[\w\d]+?)\s+(?:w\s*=\s*(\d+?|auto)\s)?(?:h\s*=\s*(\d+?|auto)\s)?(?:bg\s*=\s*(#?[\w\d]+?)\s)?(?:lh\s*=\s*(\d+?(?:px|em|%))\s)?(?:mg\s*=\s*(\d+?)\s)?(?:al\s*=\s*(center|left|right|justify)\s)?(?:rad\s*=\s*(\d+?))?\-+?\|\\,(.*?)$$"""
+       """^(.*\\,)\|\-:b\s*=\s*(\d+?)\s+(\w+?)\s+(#?[\w\d]+?)\s+(?:w\s*=\s*(\d+?|auto)\s)?(?:h\s*=\s*(\d+?|auto)\s)?(?:bg\s*=\s*(#?[\w\d]+?)\s)?(?:lh\s*=\s*(\d+?(?:px|em|%))\s)?(?:mg\s*=\s*(\d+?)\s)?(?:al\s*=\s*(center|left|right|justify)\s)?(?:rad\s*=\s*(\d+?))?\-+?\|\\,(.*?)$$""".r("before","border","style","color","width","height","background","line-h","margine","align","rad","following")
        -> ("div",fencedBox _),
-       """^(.*)\|\-:\{(.*?)\}\|(.*?)""" -> ("div",fencedBoxByClass _),
-       s"""^(.*?)$texSignStart(.*?)$texSignEnd(.*?)$$""" -> ("", laTeXConvert _),
-       """^(.*?)(([^(?:\\,)]+?\\,(:(.+?)\\,)+)+)(.*?)$$""" -> ("dl", wordDefinition _),
-       """(.*)\\,~{3,}(?:\{(.+?)\})?(\\,.+\\,)~{3,}\\,(.*)""" -> ("code", fencedCode _),
-       """^(.*?)(?:\[(.+?)\](?:\{(.+?)\})?\\,)?((\|[^-]+?)+?\|)\\,((\|:?\-{3,}:?)+?\|)\\,(((\|.+?\|?)+?\\,)+?)\\,(.*?)$$"""
+       """^(.*)\|\-:\{(.*?)\}\|(.*?)""".r("before","class","following") -> ("div",fencedBoxByClass _),
+       s"""^(.*?)$texSignStart(.*?)$texSignEnd(.*?)$$""".r("before","tex","following") -> ("", laTeXConvert _),
+       """^(.*?)(([^(?:\\,)]+?\\,(:(.+?)\\,)+)+)(.*?)$$""".r("before","seq","word","defSeq","def","following") -> ("dl", wordDefinition _),
+       """^(.*?)\\,~{3,}(?:\{([\.\_\w\d\s]+?)\})?(\\,.+?\\,)~{3,}\\,(.*?)$$""".r("before","SAttr","inTAG", "following") -> ("code", fencedCode _),//SpeedUp
+       """^(.*?)(?:\[(.+?)\](?:\{(.+?)\})?\\,)?((\|[^-]+?)+?\|)\\,((\|:?\-{3,}:?)+?\|)\\,(((\|.+?\|?)+?\\,)+?)\\,(.*?)$$""".r("before","caption","css","headSeq","head","separatorSeq","sep","bodySeq","body","b","following")
        -> ("table",surroundTableTAG _),
-       "^(.*?)`(.*)" -> ("code",surroundByCodeTAG _),
-       "^(.*)<([\\w\\d\\.\\-\\_\\+]+?)@([\\w\\d\\.\\-\\_\\+]+?)>(.*)" -> ("a", autoMailLink _),
-       "^(.*)<((?:https?|ftp):\\/\\/[\\w\\d\\.\\/]+?)>(.*)$$" -> ("a",autoURLLink _),
-       """^(.*)\[\^(.+?)\](.*)$$""" -> ("sup",insertFootnote _),
-       """(.*)\*\[(.*?)\]\{(#?[\w\d]+?)?(/#?[\w\d]+?)?(\(\+?(.*?)?(\|\+?(.*?))?\))?(\[(.*?)\])?\}(.*)"""
-       -> ("span",colorPen _),
-       "^(.*)!\\[(.+?)\\]\\[(.*?)\\](?:\\{(.+?)\\})?(.*)$$" -> ("img",referenceExpander _),
-       "^(.*)\\[(.+?)\\]\\[(.*?)\\](?:\\{(.+?)\\})?(.*)$$" -> ("a",referenceExpander _),
-       "^(.*?)!\\[(.*?)\\]\\((.+?)\\x20*?(?:\"(.+?)\")?(?:\\x20+?(\\d+?%?)?x(\\d+?%?)?)?\\)(?:\\{(.+?)\\})?(.*)$$"
+       "^(.*?)`(.*)$$".r -> ("code",surroundByCodeTAG _),//SpeedUp
+       "^(.*)<([\\w\\d\\.\\-\\_\\+]+?)@([\\w\\d\\.\\-\\_\\+]+?)>(.*)".r("before","inTAG","domain","following") -> ("a", autoMailLink _),
+       "^(.*)<((?:https?|ftp):\\/\\/[\\w\\d\\.\\/]+?)>(.*)$$".r("before","inTAG","following") -> ("a",autoURLLink _),
+       """^(.*)\[\^(.+?)\](.*)$$""".r("before","footnote","following") -> ("sup",insertFootnote _),
+       """^(.*)\*\[(.*?)\]\{(#?[\w\d]+?)?(/#?[\w\d]+?)?(\(\+?(.*?)?(\|\+?(.*?))?\))?(\[(.*?)\])?\}(.*)$$""".r("before","content","fcolor","bcolor","fstyle","size","dummy","weight","face","ffamily","following")
+       -> ("span",colorPen _), //SpeedUp
+       "^(.*)!\\[(.+?)\\]\\[(.*?)\\](?:\\{(.+?)\\})?(.*)$$".r -> ("img",referenceExpander _),
+       "^(.*)\\[(.+?)\\]\\[(.*?)\\](?:\\{(.+?)\\})?(.*)$$".r -> ("a",referenceExpander _),
+       "^(.*?)!\\[(.*?)\\]\\((.+?)\\x20*?(?:\"(.+?)\")?(?:\\x20+?(\\d+?%?)?x(\\d+?%?)?)?\\)(?:\\{(.+?)\\})?(.*)$$".r("before","alt","url","title","resX","resY","css","following")
        -> ("img", putImgTAG _),
-       "^(.*?)\\[(.*?)\\]\\((.+?)\\x20*?(?:\"(.+?)\")?\\)(?:\\{(.+?)\\})?(.*?)$$" -> ("a", surroundaHrefTAG _),
-       "^(.*?\\\\,)((>.*(?:\\\\,))+?)(.*?)$$" -> ("blockquote",surroundByBlockquoteTAG _),
-       "^(.*?)(((?:\\x20{4,}|\\t+)\\d+?\\.\\x20.+?\\\\,)+)(.*?)$$" -> ("ol",surroundByListTAG _),
-       "^(.*?)(((?:\\x20{4,}|\\t+)(?:\\*|\\+|\\-)\\x20.+?\\\\,)+)(.*?)$$" -> ("ul",surroundByListTAG _),
-       "^(.*?)(#{1,6})\\x20(.+?)(\\x20#{1,6}?(?:\\{(.*?)\\}))?\\\\,(.*?)$$" -> ("h",surroundByHeadTAG _),
-       "^(.*\\\\,)(.*?)(?:\\{(.+?)\\})?\\\\,(\\-+|=+)\\x20*\\\\,(.*?)$$" -> ("h",surroundByHeadTAGUnderlineStyle _),
-       """^(.*?)(\{toc(:.+?)?\})(.*)$$""" -> ("ul",generateTOC _),
-       "^(.*\\\\,)((?:\\-|\\*){3,}|(?:(?:\\-|\\*)\\x20){3,})(.*?)$$" -> ("hr",putHrTAG _),
-       "^(.*?)\\*\\*([^\\,]{1,64}?)\\*\\*(.*?)$$" -> ("strong",surroundByGeneralTAG _),
-       "^(.*?)\\*([^\\,]{1,64}?)\\*(.*?)$$" -> ("em",surroundByGeneralTAG _),
-       """^(.*?\\,)(%{1,6})\x20(.*?)(\\,.*?)$$""" -> ("h", autoNumberingHeader _),
-       "^(.*?\\\\,)(((?:\\x20{4,}|\\t+)(.*?\\\\,))+)(.*?)$$" -> ("code",surroundByPreCodeTAG _)
+       "^(.*?)\\[(.*?)\\]\\((.+?)\\x20*?(?:\"(.+?)\")?\\)(?:\\{(.+?)\\})?(.*?)$$".r("before","inTag","link","title","css","following") -> ("a", surroundaHrefTAG _),
+       "^(.*?\\\\,)((>\\s.*(?:\\\\,))+?)(.*?)$$".r("before","inTAG","midInTag","following") -> ("blockquote",surroundByBlockquoteTAG _),
+       "^(.*?)(((?:\\x20{4,}|\\t+)\\d+?\\.\\x20.+?\\\\,)+)(.*?)$$".r("before","elements","element","following") -> ("ol",surroundByListTAG _),
+       "^(.*?)(((?:\\x20{4,}|\\t+)(?:\\*|\\+|\\-)\\x20.+?\\\\,)+)(.*?)$$".r("before","elements","element","following") -> ("ul",surroundByListTAG _),
+       "^(.*?)(#{1,6})\\x20(.+?)(\\x20#{1,6}?(?:\\{(.*?)\\}))?\\\\,(.*?)$$".r("before","startHead","inTAG","endHead","id","following") -> ("h",surroundByHeadTAG _),
+       """^(.*?\\,)(.*?)(?:\{(.+?)\})?\\,(\-+|=+)\s*\\,(.*?)$$""".r("before","inTAG","id","style","following") -> ("h",surroundByHeadTAGUnderlineStyle _),//Speedup
+       """^(.*?)(\{toc(:.+?)?\})(.*)$$""".r("before","toc","range","following") -> ("ul",generateTOC _),
+       "^(.*\\\\,)((?:\\-|\\*){3,}|(?:(?:\\-|\\*)\\x20){3,})(.*?)$$".r("before","line","following") -> ("hr",putHrTAG _),
+       "^(.*?)\\*\\*([^\\,]{1,64}?)\\*\\*(.*?)$$".r("before","inTAG","following") -> ("strong",surroundByGeneralTAG _),
+       "^(.*?)\\*([^\\,]{1,64}?)\\*(.*?)$$".r("before","inTAG","following") -> ("em",surroundByGeneralTAG _),
+       """^(.*?\\,)(%{1,6})\x20(.*?)(\\,.*?)$$""".r("before","hSize","inTAG","following") -> ("h", autoNumberingHeader _),
+       """^(.*?\\,)(((?:\x20{4,}|\t+)(.*?\\,))+?)(.*?)$$""".r("before","seq","inTAG","midInTag","following") -> ("code",surroundByPreCodeTAG _)
        //late
        )
 
-       private def fencedBoxByClass(doc:String, regex:String, TAG:String):String = {
-               val p = new Regex(regex,"before","class","following")
-               val m = p findFirstMatchIn(doc)
+
+       def fencedBoxByClass(doc:String, regex:Regex, TAG:String):String = {
+               val m = regex findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -91,18 +97,18 @@ class BQParser {
                                return fencedBoxByClass(bef,regex,TAG) + s"""<$TAG class="$claz"> """ + _searchEndMark(fol,regex,TAG)
                        }else{
                                log error s"Class Name:$claz Not found"
-                               exit(1)
+                               exit()
                        }
                }
                doc
        }
 
-       private def _searchEndMark(doc:String,regex:String,TAG:String):String = {
+       def _searchEndMark(doc:String,regex:Regex,TAG:String):String = {
                val p2 = """^(.*?)\|_{3,}\|(.*?)$$""".r
                val m2 = p2 findFirstMatchIn(doc)
 
                if(m2 != None){
-                       val p3 = """(.*)\|\-:.*?\\,(.*)""".r
+                       val p3 = """^(.*)\|\-:.*?\\,(.*)$$""".r
                        val m3 = p3 findFirstMatchIn(m2.get.group(1))
                        if(m3 != None){
                                return fencedBox(m2.get.group(2),regex,TAG)
@@ -116,10 +122,8 @@ class BQParser {
                doc
        }
 
-       private def fencedBox(doc:String, regex:String, TAG:String):String = {
-
-               val p = new Regex(regex,"before","border","style","color","width","height","background","line-h","margine","align","rad","following")
-               val m = p findFirstMatchIn(doc)
+       def fencedBox(doc:String, regex:Regex, TAG:String):String = {
+               val m = regex findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -161,7 +165,7 @@ class BQParser {
                        }else{"10px"}
 
                        val div =
-                       s"""<$TAG style="border:$borderW$borderStyle$borderColor; width:$boxW;""" +
+                       s"""\\,<$TAG style="border:$borderW$borderStyle$borderColor; width:$boxW;""" +
                        s"""height:$boxH; background-color:$bgColor; line-height:$line_height; margine:$margine; text-align:$align; border-radius:$boxRad;"> """
 
                        return fencedBox(bef,regex,TAG) + div + _searchEndMark(fol,regex,TAG)
@@ -169,7 +173,7 @@ class BQParser {
                doc
        }
 
-       private def autoNumberingHeader(doc:String, regex:String, TAG:String):String = {
+       def autoNumberingHeader(doc:String, regex:Regex, TAG:String):String = {
                def _popTheWastes(i:Int):Stack[Tuple3[Int,Int,String]] = {
                        if(nStack.top._1 > i){
                                nStack.pop
@@ -181,8 +185,7 @@ class BQParser {
                        return _popTheWastes(i)
                }
 
-               val p = new Regex(regex,"before","hSize","inTAG","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -193,7 +196,7 @@ class BQParser {
                        val headSize = if(sizeCheck != 0 && sizeCheck - 1 < nRange._2){sizeCheck - 1}else{
                                log error "Auto Numbering header FATAL Error. % anotation overflowed. Check nrange value and % sequences again. You can use sequence % - " + "%" * (nRange._2 - nRange._1)
                                log debug nRange
-                               exit(-1)
+                               exit()
                        }
 
                        if(nStack.isEmpty){
@@ -201,7 +204,7 @@ class BQParser {
                                        nStack.push(Tuple3[Int,Int,String](headSize,1,"." + inTAG))
                                }else{
                                        log error "Auto numbering header Error. {nrange..} notation is not set, but found % anotation. You can use sequence % - " + "%" * (nRange._2 - nRange._1)
-                                       exit(-1)
+                                       exit()
                                }
                        }else if(nStack.top._1 < headSize){
                                nStack.push(Tuple3[Int,Int,String](headSize,1,"." + inTAG))
@@ -221,7 +224,7 @@ class BQParser {
                doc
        }
 
-       private def autoNumberSetting(doc:String):String = {
+       def autoNumberSetting(doc:String):String = {
                val p = """^(.*)(\{nrange(:h?\d?\-h?\d?)?\})(.*)$$""".r
                val m = p findFirstMatchIn(doc)
                if(m != None){
@@ -247,10 +250,9 @@ class BQParser {
                doc
        }
 
-       private def laTeXConvert(doc:String, regex:String, TAG:String):String = {
+       def laTeXConvert(doc:String, regex:Regex, TAG:String):String = {
                if(doc == ""){return ""}
-               val p = new Regex(regex, "before","tex","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -264,13 +266,12 @@ class BQParser {
                doc
        }
 
-       private def colorPen(doc:String, regex:String, TAG:String):String = {
-               lazy val fontSize = Map[Int,String](0 -> "medium", 1 -> "larger", 2 -> "large", 3 -> "x-large", 4 -> "xx-large",
+       def colorPen(doc:String, regex:Regex, TAG:String):String = {
+               val fontSize = Map[Int,String](0 -> "medium", 1 -> "larger", 2 -> "large", 3 -> "x-large", 4 -> "xx-large",
                                                                                                                  -1 -> "smaller", -2 -> "small", -3 -> "x-small", -4 -> "xx-small")
-               lazy val fontWeight = Map(0 -> "normal", 1 -> "bolder", 2 -> "bold" ,-1 -> "light")
+               val fontWeight = Map(0 -> "normal", 1 -> "bolder", 2 -> "bold" ,-1 -> "light")
                if(doc == ""){return ""}
-               val p = new Regex(regex, "before","content","fcolor","bcolor","fstyle","size","dummy","weight","face","ffamily","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -318,7 +319,7 @@ class BQParser {
                doc
        }
 
-       private def generateTOC(doc:String, regex:String, TAG:String):String = {
+       def generateTOC(doc:String, regex:Regex, TAG:String):String = {
                log debug doc
 
                def _checkRange(start:Option[String],end:Option[String],default:Tuple2[Int,Int]):Tuple2[Int,Int] = {
@@ -328,8 +329,7 @@ class BQParser {
                }
 
                val text = ""
-               val p = new Regex(regex, "before","toc","range","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
                var minmax = (1,6)
                if(m != None){
                        val bef = m.get.group("before")
@@ -376,7 +376,7 @@ class BQParser {
 
                doc
        }
-       private def putHeaderID(doc:String,min:Int,max:Int):String ={
+       def putHeaderID(doc:String,min:Int,max:Int):String ={
                if(doc == ""){return ""}
                var text = ""
                for((e,i) <- doc.split("""\\,""").zipWithIndex){
@@ -397,7 +397,7 @@ class BQParser {
                text
        }
 
-       private def makeHeaderMap(doc:String,minH:Integer,maxH:Integer):List[Tuple4[Integer,Integer,Option[String],String]] = {
+       def makeHeaderMap(doc:String,minH:Integer,maxH:Integer):List[Tuple4[Integer,Integer,Option[String],String]] = {
                var headList = List[Tuple4[Integer,Integer,Option[String],String]]()
                for((line,no) <- doc.split("""\\,""").zipWithIndex){
                        log debug "line=" + line +" No=" + no
@@ -419,11 +419,10 @@ class BQParser {
                headList.reverse
        }
 
-       private def wordDefinition(doc:String, regex:String, TAG:String):String = {
+       def wordDefinition(doc:String, regex:Regex, TAG:String):String = {
            log debug "***" + doc
                if(doc == ""){return ""}
-               val p = new Regex(regex,"before","seq","word","defSeq","def","following")
-               val m = p.findFirstMatchIn(doc)
+               val m = regex.findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -454,18 +453,17 @@ class BQParser {
                }
                doc
        }
-       private def insertFootnote(doc:String, regex:String, TAG:String):String = {
+       def insertFootnote(doc:String, regex:Regex, TAG:String):String = {
                if(doc == ""){return ""}
 
-               val p = new Regex(regex,"before","footnote","following")
-               val m = p.findFirstMatchIn(doc)
+               val m = regex.findFirstMatchIn(doc)
                if(m != None){
                        val bef = m.get.group("before")
                        var fnote = m.get.group("footnote")
                        val fol = m.get.group("following")
                        if(footnoteMap.contains(fnote)){
                                val link = footnoteMap(fnote)._1
-                               lazy val definition = footnoteMap(fnote)._2
+                               val definition = footnoteMap(fnote)._2
 
                                return insertFootnote(bef,regex,TAG) + s"""<$TAG id=\"$fnote\"><a href=\"#$link\" style="text-decoration:none">[$fnote]</a></sup>""" +
                                        insertFootnote(fol,regex,TAG)
@@ -476,7 +474,7 @@ class BQParser {
                doc
        }
 
-       private def gatheringFootnotesDefinition(doc:String):String = {
+       def gatheringFootnotesDefinition(doc:String):String = {
                val p = new Regex("""^(.*)\[\^(.*?)\]:(.*?)\\,(.*)$$""","before","landMark","definition","following")
                val m = p findFirstMatchIn(doc)
 
@@ -496,20 +494,20 @@ class BQParser {
                doc
        }
 
-       private def insertFootnoteDefinitions(doc:LinkedHashMap[String,Tuple2[String,String]]):String = {
-               lazy val head = """<footer><nav>\,<h2 id="footnotes">Footnotes</h2><hr />\,<ul style="list-style:none">\,"""
+       def insertFootnoteDefinitions(doc:LinkedHashMap[String,Tuple2[String,String]]):String = {
+               val head = """<footer><nav>\,<h2 id="footnotes">Footnotes</h2><hr />\,<ul style="list-style:none">\,"""
                val contents =
                        for((key,t2) <- doc.toList.reverse)yield(s"""<li id="${t2._1}"><p><em>$key: </em>${t2._2}<a href="#$key">&laquo;</a></p>""")
-               lazy val tail = "</ul></nav></footer>"
+               val tail = "</ul></nav></footer>"
                if(contents.size > 0){
                        return head + contents.mkString("\\,") + tail
                }else{""}
        }
 
-       private def fencedCode(doc:String, regex:String, TAG:String):String = {
+       def fencedCode(doc:String, regex:Regex, TAG:String):String = {
+         val start = System.currentTimeMillis()
            if(doc == ""){return ""}
-               val p = new Regex(regex, "before",  "SAttr", "inTAG", "following")
-               val m = p.findFirstMatchIn(doc)
+               val m = regex.findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -520,15 +518,15 @@ class BQParser {
                        if(Option(m.get.group("SAttr")) != None){
                                specialAttr = decideClassOrStyle(doc,m.get.group("SAttr"))
                        }
-
+                       log debug (System.currentTimeMillis() - start).toString + " msec"
                        return fencedCode(bef,regex,"code") +
                                s"<pre $specialAttr><$TAG>\\\\," + ltgtExpand(inCode) + s"</$TAG></pre>" +
                                        fencedCode(fol,regex,TAG)
                }else{return doc}
-               doc
+
        }
 
-       private def surroundTableTAG(doc:String, regex:String, TAG:String):String = {
+       def surroundTableTAG(doc:String, regex:Regex, TAG:String):String = {
                def _normalize(text:String):String = {
                  var retStr = text
                  if(retStr.startsWith("|")){
@@ -547,8 +545,7 @@ class BQParser {
                if(doc == ""){return ""}
 
                log debug "***" + doc
-               val p = new Regex(regex, "before","caption","css","headSeq","head","separatorSeq","sep","bodySeq","body","b","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -590,7 +587,7 @@ class BQParser {
                                val headList = heads.toList
                                if(headList.size != alignList.size){
                                        log error "Table header is wrong.:" + headList
-                                       exit(-1)
+                                       exit()
                                }
 
 
@@ -627,11 +624,9 @@ class BQParser {
                doc
        }
 
-       private def autoMailLink(doc:String, regex:String, TAG:String):String = {
+       def autoMailLink(doc:String, regex:Regex, TAG:String):String = {
                if(doc == ""){return ""}
-
-               val p = new Regex(regex, "before","inTAG","domain","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
 
                if(m!= None){
                        val bef = m.get.group("before")
@@ -645,11 +640,10 @@ class BQParser {
                }
                doc
        }
-       private def autoURLLink(doc:String, regex:String, TAG:String):String = {
+       def autoURLLink(doc:String, regex:Regex, TAG:String):String = {
                if(doc == ""){return ""}
 
-               val p = new Regex(regex, "before","inTAG","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
 
                if(m!= None){
                        val bef = m.get.group("before")
@@ -661,11 +655,10 @@ class BQParser {
                }
                doc
        }
-       private def putImgTAG(doc:String, regex:String, TAG:String):String = {
+       def putImgTAG(doc:String, regex:Regex, TAG:String):String = {
                if(doc == ""){return ""}
 
-               val p = new Regex(regex,"before","alt","url","title","resX","resY","css","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
 
                if(m != None){
                        val bef = m.get.group("before")
@@ -679,22 +672,22 @@ class BQParser {
                doc
        }
 
-       private def getResolutionX(resX:String):String = Option(resX) match{
+       def getResolutionX(resX:String):String = Option(resX) match{
                case None => return ""
                case Some(x) => return s" width=$resX "
                case _ =>
                        log error "unknown parameter has found." + resX
-                       exit(-1)
+                       exit()
        }
 
-       private def getResolutionY(resY:String):String = Option(resY) match{
+       def getResolutionY(resY:String):String = Option(resY) match{
                case None => return ""
                case Some(y) => return s" height=$resY "
                case _ =>
                        log error "unknown parameter has found." + resY
-                       exit(-1)
+                       exit()
        }
-       private def searchCSSClassName(doc:String,cssClass:String):Boolean = {
+       def searchCSSClassName(doc:String,cssClass:String):Boolean = {
                val p = """(?i)<link.*?type=\"text\/css\".*?href=\"(.*?)\".*?>""".r
                val m = p findFirstMatchIn(doc)
 
@@ -711,11 +704,10 @@ class BQParser {
                false
        }
 
-       private def surroundByCodeTAG(doc:String, regex:String, TAG:String):String = {
-           def _surroundByCodeTAG(doc:String,regex:String,innerSign:String,TAG:String):String = {
+       def surroundByCodeTAG(doc:String, regex:Regex, TAG:String):String = {
+           def _surroundByCodeTAG(doc:String,regex:Regex,innerSign:String,TAG:String):String = {
                if(doc.contains(innerSign)){
-                       val p = regex.r
-                       val m = p.findFirstMatchIn(doc)
+                       val m = regex.findFirstMatchIn(doc)
 
                        if(m != None){
                                val bef = m.get.group(1)
@@ -729,13 +721,13 @@ class BQParser {
                                }else{
                                        follow = fol
                                }
-                               log debug "**>" + follow
-                               log debug "==>" + sign
-                               val p2 = s"""^([^(?:\\,)]+?)$sign(.*)$$""".r
+                               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)
+                                       log debug ">>>> " + m2.get.group(1)
                                        return _surroundByCodeTAG(bef, regex, "`", TAG) + s"<$TAG>" + ltgtExpand(m2.get.group(1)) + s"</$TAG>" +
                                                _surroundByCodeTAG(m2.get.group(2), regex, "`", TAG)
                                }else{
@@ -756,8 +748,8 @@ class BQParser {
     _surroundByCodeTAG(doc,regex,"`",TAG)
        }
 
-       private def referenceExpander(doc:String, regex:String, TAG:String):String = {
-               val m = regex.r.findFirstMatchIn(doc)
+       def referenceExpander(doc:String, regex:Regex, TAG:String):String = {
+               val m = regex.findFirstMatchIn(doc)
                def expandAttribute(value:String):String = value match{
                        case "" => return ""
                        case _ => return value
@@ -790,7 +782,7 @@ class BQParser {
                                                referenceExpander(m.get.group(5), regex, TAG)
                                        case _ =>
                                                log error "Unknown Expand TAG from Reference"
-                                               exit(-1)
+                                               exit()
                                }
                        }else{
                          log warn "Link definition was not found : " + key
@@ -802,7 +794,7 @@ class BQParser {
 
        }
 
-       private def urlDefinitions(doc:String):String = {
+       def urlDefinitions(doc:String):String = {
                def _urlDefinitions(text:String):String = {
                    var bef = ""
                    var fol = ""
@@ -854,7 +846,7 @@ class BQParser {
                _urlDefinitions(doc)
        }
 
-       private def decideClassOrStyle(doc:String,className:String):String = {
+       def decideClassOrStyle(doc:String,className:String):String = {
                if(className == "" || className == null){
                        return ""
                }
@@ -872,7 +864,7 @@ class BQParser {
                }
        }
 
-       private def getTitleName(title:String):String = {
+       def getTitleName(title:String):String = {
                if(title == ""| title == null){
                        return ""
                }
@@ -880,9 +872,8 @@ class BQParser {
                return s"""title=\"$title\" """
        }
 
-       private def surroundaHrefTAG(doc:String,regex:String,TAG:String):String = {
-               val p = new Regex(regex,"before","inTag","link","title","css","following")
-               val m = p findFirstMatchIn(doc)
+       def surroundaHrefTAG(doc:String,regex:Regex,TAG:String):String = {
+               val m = regex findFirstMatchIn(doc)
 
                var bef = ""
                var fol = ""
@@ -902,9 +893,8 @@ class BQParser {
                doc
        }
 
-       private def putHrTAG(doc:String, regex:String, TAG:String):String = {
-               val p = new Regex(regex,"before","line","following")
-               val m = p findFirstMatchIn(doc)
+       def putHrTAG(doc:String, regex:Regex, TAG:String):String = {
+               val m = regex findFirstMatchIn(doc)
 
                log debug doc
 
@@ -921,12 +911,11 @@ class BQParser {
          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)
+       def surroundByPreCodeTAG(doc:String, regex:Regex, TAG:String):String = {
+               val m = regex findFirstMatchIn(doc)
                log debug "[" + doc + "]"
 
-               val p2 = """(.*)<pre><code>(.+)</code></pre>(.*)""".r
+               val p2 = """^(.*)<pre><code>(.+?)</code></pre>(.*)$$""".r
                val m2 = p2 findFirstMatchIn(doc)
                if(m2 != None){
                        return surroundByPreCodeTAG(m2.get.group(1), regex, TAG) +
@@ -960,13 +949,12 @@ class BQParser {
          doc
        }
 
-       private def ltgtExpand(doc:String):String = {
+       def ltgtExpand(doc:String):String = {
                return doc.replaceAll("&","&amp").replaceAll("<","&gt;").replaceAll(">","&gt;")
        }
 
-       private def surroundByBlockquoteTAG(doc:String, regex:String, TAG:String):String = {
-         val p = new Regex(regex, "before","inTAG","midInTag","following")
-         val m = p findFirstMatchIn(doc)
+       def surroundByBlockquoteTAG(doc:String, regex:Regex, TAG:String):String = {
+         val m = regex findFirstMatchIn(doc)
          log debug "[" + doc + "]"
 
          var bef = ""
@@ -1018,9 +1006,8 @@ class BQParser {
          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)
+       def surroundByListTAG(doc:String, regex:Regex, TAG:String):String = {
+               val m = regex findFirstMatchIn(doc)
                var s = ""
                var bef = ""
                var fol = ""
@@ -1131,12 +1118,11 @@ class BQParser {
                }else{doc}
        }
 
-       private def surroundByHeadTAGUnderlineStyle(doc:String, regex:String, TAG:String):String = {
+       def surroundByHeadTAGUnderlineStyle(doc:String, regex:Regex, TAG:String):String = {
          if(doc == ""){return doc}
 
          log debug "-->" + doc
-         val p = new Regex(regex, "before","inTAG","id","style","following")
-         val m = p findFirstMatchIn(doc)
+         val m = regex findFirstMatchIn(doc)
          var bef = ""
          var fol = ""
          var contentStr = ""
@@ -1164,12 +1150,11 @@ class BQParser {
          doc
        }
 
-       private def surroundByHeadTAG(doc:String, regex:String, TAG:String):String = {
+       def surroundByHeadTAG(doc:String, regex:Regex, TAG:String):String = {
                if(doc == ""){return doc}
 
                log debug "--> " + doc
-               val p = new Regex(regex, "before","startHead","inTAG","endHead","id","following")
-               val m = p findFirstMatchIn(doc)
+               val m = regex findFirstMatchIn(doc)
                var contentStr = ""
 
                if(m != None){
@@ -1205,11 +1190,10 @@ class BQParser {
          doc
 }
 
-       private def surroundByGeneralTAG(doc:String, regex:String, TAG:String):String = {
+       def surroundByGeneralTAG(doc:String, regex:Regex, TAG:String):String = {
          if(doc == ""||Option(doc) == None){return ""}
          log debug doc
-         val p = new Regex(regex,"before","inTAG","following")
-         val m = p findFirstMatchIn(doc)
+         val m = regex findFirstMatchIn(doc)
          if(m != None){
              var bef = ""
              var fol = ""
@@ -1246,12 +1230,14 @@ class BQParser {
                val bodyTAG = "body"
                val htmlTAG = "html"
                var md = preProcessors(markdown + "\\,")
-               val l = md.length()
-               for(k <- Syntax keys){
-                md = Syntax(k)._2(md, k, Syntax(k)._1)
-                log debug  Syntax(k)._1 + "***" + md
-               }
-               //log info md
+
+        for(k <- Syntax keys){
+          val start = System.currentTimeMillis()
+          md = Syntax(k)._2(md, k, Syntax(k)._1)
+          log debug k + " :::: " + (System.currentTimeMillis() - start) + " msec"
+        }
+
+               log debug md
                md = backslashEscape(md)
                md = paragraphize(md)
                log debug urlDefMap
@@ -1259,6 +1245,7 @@ class BQParser {
                md += insertFootnoteDefinitions(footnoteMap)
                val header = constructHEADER(markdown)
                s"${docType}\n${header}\n<${htmlTAG}>\n<${bodyTAG}>\n${md.replaceAll("\\\\,","\n")}\n</${bodyTAG}>\n</${htmlTAG}>"
+
        }
 
        def toDOM(markdown:String):org.w3c.dom.Document = {
@@ -1272,47 +1259,79 @@ class BQParser {
 
 
        private def paragraphize(doc:String):String = {
-               if(doc == ""){return ""}
-               var text = ListBuffer.empty[String]
-               val textList = doc.split("""\\,""")
-
-               val BlockElem = new HTMLMap BLOCKTags
-               var tag = ""
-               val blockElements = Stack.empty[String]
-               var blockDepth = 0
-
-               for(l <- textList){
-                       if( blockElements.size > 0 ){
-                               val pb = s"""</${blockElements.top}>""".r
-                               val mb = pb findFirstMatchIn(l)
-
-                               if(l != ""){text += l}
-                               if(mb != None){
-                                       blockElements.pop
-                               }
-                       }else{
-                               val p = """<([\w\d]+).*?>""".r
-                               val m = p findFirstMatchIn(l)
-
-                               if(m != None){
-                                       tag = m.get.group(1)
-                                       if(BlockElem contains(tag)){
-                                         val pe = s"""</$tag>""".r
-                                         val me = pe findFirstMatchIn(l)
-                                         if(me == None){
-                                                blockElements.push(tag)
-                                         }
-                                         if(l != ""){text += l}
-                                       }else{
-                                         if(l != ""){text += "<p>" + l + "</p>"}
-                                       }
-                               }else{
-                                 if(l != ""){text += "<p>" + l + "</p>"}
+         if(doc == ""){return ""}
+         val BlockElem = new HTMLMap BLOCKTags
+         val InlineElem = new HTMLMap INLINETags
+         var tag = ""
+         val blockElements = Stack.empty[String]
+
+         def _paragraphize(strList:List[String],TAG:String):List[String] = {
+                       if(strList.isEmpty){return strList}
+                       log debug ">>> " + strList.head
+                       val p = """<([\w\d]+)\s?.*?>""".r
+                       val m = p findFirstMatchIn(strList.head)
+                       if(m != None && BlockElem.contains(m.get.group(1))){
+                               val pe = s"""</${m.get.group(1)}>""".r
+                               val me = pe findFirstMatchIn(strList.head)
+                               if(me == None){
+                                       blockElements.push(m.get.group(1))
                                }
                        }
-               }
-         text mkString("""\,""")
 
+                       if(blockElements.size > 0){
+                            val pb = s"""</${blockElements.top}>""".r
+                            val mb = pb findFirstMatchIn(strList.head)
+
+                            if(mb != None){
+                                if(!strList.head.isEmpty()){
+                                   log debug "0.1: " + blockElements + " : " +  strList.head
+                                       return strList.head::_paragraphize(strList.tail,blockElements.pop)
+                                }
+                            }else{
+                              if(!strList.head.isEmpty()){
+                                   log debug "0.2: "  + blockElements + " : " +  strList.head
+                                       return strList.head::_paragraphize(strList.tail,"")
+                                }
+                            }
+                       }
+
+                       if(m != None){
+                         tag = m.get.group(1)
+                         log debug "tag = " + tag + "****"
+                         if(BlockElem contains(tag)){
+                               val pe = s"""</$tag>""".r
+                               val me = pe findFirstMatchIn(strList.head)
+                               if(me == None){
+                                 blockElements.push(tag)
+                               }
+                               if(!strList.head.isEmpty()){
+                                   log debug "1: " + blockElements + " : " + strList.head
+                                       return strList.head::_paragraphize(strList.tail,tag)
+                               }
+                         }else{
+                           if(blockElements.size > 0){
+                             if(!strList.head.isEmpty()){
+                                   log debug "2.1: " + blockElements + " : " +  strList.head
+                               return  strList.head::_paragraphize(strList.tail,tag)
+                            }
+                           }else{
+                             if(!strList.head.isEmpty()){
+                                   log debug "2.2: <p>" + blockElements + " : " + strList.head
+                               return "<p>" + strList.head + "</p>" ::_paragraphize(strList.tail,"")
+                            }
+                           }
+
+                         }
+                       }else{
+                             if(!strList.head.isEmpty()){
+                               log debug "3: " + "<p> :" + blockElements + " : " + strList.head
+                               return "<p>" + strList.head + "</p>" ::_paragraphize(strList.tail,tag)
+                            }
+                         }
+
+                 return _paragraphize(strList.tail,"")
+         }
+         return _paragraphize(doc.split("""\\,""").toList,"").mkString("""\,""")
        }
 
        private def backslashEscape(doc:String):String = {
@@ -1328,4 +1347,4 @@ class BQParser {
                return bef
        }
 
-}
\ No newline at end of file
+}
index 1a5e16a..8c95aec 100644 (file)
@@ -21,85 +21,85 @@ class HTMLMap{
     "address","blockquote","center","div","dl","fieldset","form","h1","h2","h3","h4","h5","h6",
     "header","noframes","noscript","ol","p","pre","table","ul")
 
-  private val HTMLTag = LinkedHashMap(
-    "hr"->Tuple2((None),passThrough _),
-    "br"->Tuple2((None),passThrough _),
-    "!--"->Tuple2(("-->"),passThrough _),
-    "link"->Tuple2((">"),specialCharConvert _),
-    "style"->Tuple2((">"),passThrough _),
-    "basefont"->Tuple2((">"),passThrough _),
-    "html"->Tuple2(("</html>"),passThrough _),
-    "head"->Tuple2(("</head>"),specialCharConvert _),
-    "body"->Tuple2(("</body>"),specialCharConvert _),
-    "title"->Tuple2(("</title>"),specialCharConvert _),
-    "isinindex"->Tuple2(("</isinindex>"),specialCharConvert _),
-    "base"->Tuple2(("</base>"),specialCharConvert _),
-    "meta"->Tuple2(("</meta>"),passThrough _),
-    "script"->Tuple2(("</script>"),passThrough _),
-    "hn"->Tuple2(("</hn>"),passThrough _),
-    "h1"->Tuple2(("</h1>"),specialCharConvert _),
-    "h2"->Tuple2(("</h2>"),specialCharConvert _),
-    "h3"->Tuple2(("</h3>"),specialCharConvert _),
-    "h4"->Tuple2(("</h4>"),specialCharConvert _),
-    "h5"->Tuple2(("</h5>"),specialCharConvert _),
-    "h6"->Tuple2(("</h6>"),specialCharConvert _),
-    "abbr"->Tuple2(("</abbr>"),specialCharConvert _),
-    "acronym"->Tuple2(("</acronym>"),specialCharConvert _),
-    "p"->Tuple2(("</p>"),specialCharConvert _),
-    "center"->Tuple2(("</center>"),specialCharConvert _),
-    "div"->Tuple2(("</div>"),specialCharConvert _),
-    "pre"->Tuple2(("</pre>"),passThrough _),
-    "blockquote"->Tuple2(("</blockquote>"),specialCharConvert _),
-    "address"->Tuple2(("</address>"),passThrough _),
-    "noscript"->Tuple2(("</noscript>"),passThrough _),
-    "font"->Tuple2(("</font>"),specialCharConvert _),
-    "i"->Tuple2(("</i>"),specialCharConvert _),
-    "tt"->Tuple2(("</tt>"),specialCharConvert _),
-    "abbr"->Tuple2(("</abbr>"),specialCharConvert _),
-    "b"->Tuple2(("</b>"),specialCharConvert _),
-    "u"->Tuple2(("</u>"),specialCharConvert _),
-    "strike"->Tuple2(("</strike>"),specialCharConvert _),
-    "big"->Tuple2(("</big>"),specialCharConvert _),
-    "small"->Tuple2(("</small>"),specialCharConvert _),
-    "sub"->Tuple2(("</sub>"),specialCharConvert _),
-    "sup"->Tuple2(("</sup>"),specialCharConvert _),
-    "em"->Tuple2(("</em>"),specialCharConvert _),
-    "strong"->Tuple2(("<strong>"),specialCharConvert _),
-    "code"->Tuple2(("</code>"),passThrough _),
-    "dfn"->Tuple2(("</dfn>"),specialCharConvert _),
-    "samp"->Tuple2(("</samp>"),passThrough _),
-    "kbd"->Tuple2(("</kbd>"),passThrough _),
-    "var"->Tuple2(("<var>"),passThrough _),
-    "ins"->Tuple2(("</ins>"),specialCharConvert _),
-    "del"->Tuple2(("</del>"),specialCharConvert _),
-    "cite"->Tuple2(("</cite>"),passThrough _),
-    "ul"->Tuple2(("</ul>"),specialCharConvert _),
-    "ol"->Tuple2(("</ol>"),specialCharConvert _),
-    "li"->Tuple2(("<li>"),specialCharConvert _),
-    "dt"->Tuple2(("</dt>"),specialCharConvert _),
-    "dd"->Tuple2(("</dd>"),specialCharConvert _),
-    "object"->Tuple2(("</object>"),specialCharConvert _),
-    "table"->Tuple2(("</table>"),specialCharConvert _),
-    "tr"->Tuple2(("</tr>"),specialCharConvert _),
-    "td"->Tuple2(("</td>"),specialCharConvert _),
-    "caption"->Tuple2(("</caption>"),specialCharConvert _),
-    "a"->Tuple2(("</a>",">"),specialCharConvert _),
-    "img"->Tuple2((">"),specialCharConvert _),
-    "map"->Tuple2(("</map>"),specialCharConvert _),
-    "area"->Tuple2((">"),passThrough _),
-    "form"->Tuple2(("</form>"),passThrough _),
-    "input"->Tuple2((">"),passThrough _),
-    "select"->Tuple2(("</select>"),passThrough _),
-    "option"->Tuple2(("</option>"),passThrough _),
-    "textarea"->Tuple2(("</textarea>"),specialCharConvert _),
-    "applet"->Tuple2(("</applet>"),passThrough _),
-    "param"->Tuple2(("</param>"),passThrough _),
-    "frameset"->Tuple2(("</frameset>"),passThrough _),
-    "frame"->Tuple2(("</frame>"),specialCharConvert _),
-    "noframes"->Tuple2(("</noframes>"),specialCharConvert _),
-    "bdo"->Tuple2(("</bdo>"),specialCharConvert _),
-    "span"->Tuple2(("</span>"),specialCharConvert _),
-    "NOTAG"->Tuple2(("---"),specialCharConvert _)
+  private val HTMLTag = LinkedHashMap[String,(List[String],(String)=>String)](
+    "hr"->Tuple2(List("xx"),passThrough _),
+    "br"->Tuple2(List("xx"),passThrough _),
+    "!--"->Tuple2(List("-->"),passThrough _),
+    "link"->Tuple2(List(">"),specialCharConvert _),
+    "style"->Tuple2(List(">"),passThrough _),
+    "basefont"->Tuple2(List(">"),passThrough _),
+    "html"->Tuple2(List("</html>"),passThrough _),
+    "head"->Tuple2(List("</head>"),specialCharConvert _),
+    "body"->Tuple2(List("</body>"),specialCharConvert _),
+    "title"->Tuple2(List("</title>"),specialCharConvert _),
+    "isinindex"->Tuple2(List("</isinindex>"),specialCharConvert _),
+    "base"->Tuple2(List("</base>"),specialCharConvert _),
+    "meta"->Tuple2(List("</meta>"),passThrough _),
+    "script"->Tuple2(List("</script>"),passThrough _),
+    "hn"->Tuple2(List("</hn>"),passThrough _),
+    "h1"->Tuple2(List("</h1>"),specialCharConvert _),
+    "h2"->Tuple2(List("</h2>"),specialCharConvert _),
+    "h3"->Tuple2(List("</h3>"),specialCharConvert _),
+    "h4"->Tuple2(List("</h4>"),specialCharConvert _),
+    "h5"->Tuple2(List("</h5>"),specialCharConvert _),
+    "h6"->Tuple2(List("</h6>"),specialCharConvert _),
+    "abbr"->Tuple2(List("</abbr>"),specialCharConvert _),
+    "acronym"->Tuple2(List("</acronym>"),specialCharConvert _),
+    "p"->Tuple2(List("</p>"),specialCharConvert _),
+    "center"->Tuple2(List("</center>"),specialCharConvert _),
+    "div"->Tuple2(List("</div>"),specialCharConvert _),
+    "pre"->Tuple2(List("</pre>"),passThrough _),
+    "blockquote"->Tuple2(List("</blockquote>"),specialCharConvert _),
+    "address"->Tuple2(List("</address>"),passThrough _),
+    "noscript"->Tuple2(List("</noscript>"),passThrough _),
+    "font"->Tuple2(List("</font>"),specialCharConvert _),
+    "i"->Tuple2(List("</i>"),specialCharConvert _),
+    "tt"->Tuple2(List("</tt>"),specialCharConvert _),
+    "abbr"->Tuple2(List("</abbr>"),specialCharConvert _),
+    "b"->Tuple2(List("</b>"),specialCharConvert _),
+    "u"->Tuple2(List("</u>"),specialCharConvert _),
+    "strike"->Tuple2(List("</strike>"),specialCharConvert _),
+    "big"->Tuple2(List("</big>"),specialCharConvert _),
+    "small"->Tuple2(List("</small>"),specialCharConvert _),
+    "sub"->Tuple2(List("</sub>"),specialCharConvert _),
+    "sup"->Tuple2(List("</sup>"),specialCharConvert _),
+    "em"->Tuple2(List("</em>"),specialCharConvert _),
+    "strong"->Tuple2(List("<strong>"),specialCharConvert _),
+    "code"->Tuple2(List("</code>"),passThrough _),
+    "dfn"->Tuple2(List("</dfn>"),specialCharConvert _),
+    "samp"->Tuple2(List("</samp>"),passThrough _),
+    "kbd"->Tuple2(List("</kbd>"),passThrough _),
+    "var"->Tuple2(List("<var>"),passThrough _),
+    "ins"->Tuple2(List("</ins>"),specialCharConvert _),
+    "del"->Tuple2(List("</del>"),specialCharConvert _),
+    "cite"->Tuple2(List("</cite>"),passThrough _),
+    "ul"->Tuple2(List("</ul>"),specialCharConvert _),
+    "ol"->Tuple2(List("</ol>"),specialCharConvert _),
+    "li"->Tuple2(List("<li>"),specialCharConvert _),
+    "dt"->Tuple2(List("</dt>"),specialCharConvert _),
+    "dd"->Tuple2(List("</dd>"),specialCharConvert _),
+    "object"->Tuple2(List("</object>"),specialCharConvert _),
+    "table"->Tuple2(List("</table>"),specialCharConvert _),
+    "tr"->Tuple2(List("</tr>"),specialCharConvert _),
+    "td"->Tuple2(List("</td>"),specialCharConvert _),
+    "caption"->Tuple2(List("</caption>"),specialCharConvert _),
+    "a"->Tuple2(List("</a>",">"),specialCharConvert _),
+    "img"->Tuple2(List(">"),specialCharConvert _),
+    "map"->Tuple2(List("</map>"),specialCharConvert _),
+    "area"->Tuple2(List(">"),passThrough _),
+    "form"->Tuple2(List("</form>"),passThrough _),
+    "input"->Tuple2(List(">"),passThrough _),
+    "select"->Tuple2(List("</select>"),passThrough _),
+    "option"->Tuple2(List("</option>"),passThrough _),
+    "textarea"->Tuple2(List("</textarea>"),specialCharConvert _),
+    "applet"->Tuple2(List("</applet>"),passThrough _),
+    "param"->Tuple2(List("</param>"),passThrough _),
+    "frameset"->Tuple2(List("</frameset>"),passThrough _),
+    "frame"->Tuple2(List("</frame>"),specialCharConvert _),
+    "noframes"->Tuple2(List("</noframes>"),specialCharConvert _),
+    "bdo"->Tuple2(List("</bdo>"),specialCharConvert _),
+    "span"->Tuple2(List("</span>"),specialCharConvert _),
+    "NOTAG"->Tuple2(List("---"),specialCharConvert _)
 )
 
   private val specialChar = LinkedHashMap(
@@ -109,7 +109,7 @@ 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;","""\\&""".r->"&amp;")
+    """!in""".r -> "&notin;", """\\<""".r->"&lt;","""\\>""".r->"&gt;","""\\&""".r->"&amp;","""/\*""".r ->"/&lowast;","""\*/""".r -> "&lowast;/")
 
 
   private def passThrough(text:String):String = {text}
@@ -121,6 +121,16 @@ class HTMLMap{
     }
     str
   }
+  
+  
+  def specialCharConvert(text:List[String]):List[String] = {
+    if(text.isEmpty){return text}
+    var str = text.head
+    for(elem <- specialChar.keys){
+       str = elem replaceAllIn(str,m => specialChar(elem))
+    }
+    return str::specialCharConvert(text.tail)
+  }
 
 /*
   def ampConverter(text:String):String = {
@@ -172,11 +182,12 @@ class HTMLMap{
   }
  */
 
-  def htmlTAGFilter(doc:String):String = {
-    if(doc == ""){return ""}
+  def htmlTAGFilter(text:String):String = {
+    val start = System.currentTimeMillis()
+    if(text == ""){return ""}
     val node = new BQParser
-
-
+    val doc = text
+    //log info "specialChar " + (System.currentTimeMillis() - start) + " msec"
     val NORMALIZE: Regex = """(?i)(.+)""".r
 
     log debug "***" + doc
@@ -187,51 +198,58 @@ class HTMLMap{
 
       for (eT <- Iterator(HTMLTag(elem) _1)){
        eT match{
-       case None =>
-               val p = new Regex(s"""(?i)^(.*?)<${elem}\\s*[>|\\/>](.*?)$$""","before","following")
+       case NORMALIZE("xx") =>
+               val p = s"""(?i)^(.*?)<${elem}\\s*(?:>|/>)(.*?)$$""".r("before","following")
                val m = p findFirstMatchIn(doc)
                if(m != None){
+                     log info "in TAGFilter None " + (System.currentTimeMillis() - start) + " msec"
                        return htmlTAGFilter(m.get.group("before")) + "<" +
                                        elem + " />" + htmlTAGFilter(m.get.group("following"))
                }
        case NORMALIZE("-->") =>
-         val p = new Regex(s"""^(.*?)<${elem}.*?${endTag}(.*?)$$""","before","following")
+         val p = s"""^(.*?)<${elem}.*?${endTag}(.*?)$$""".r("before","following")
          val m = p findFirstMatchIn(doc)
          if(m != None){
+           log info "in TAGFilter --> " + (System.currentTimeMillis() - start) + " msec"
                return htmlTAGFilter(m.get.group("before")) + htmlTAGFilter(m.get.group("following"))
          }
        case NORMALIZE(">") =>
-               val p = new Regex(s"""(?i)^(.*?)<${elem}\\s((\\w+=\\"(.*?)\\"\\s??)+)\\/??>(.*?)$$""",
+               val p = s"""(?i)^(.*?)<${elem}\\s((\\w+=\\"(.*?)\\"\\s?)+)\\/?>(.*?)$$""".r(
                                "before","attributes","attribute","contents","following")
                val m = p findFirstMatchIn(doc)
                if(m != None){
+                     log info "in TAGFilter > " + (System.currentTimeMillis() - start) + " msec"
                  return htmlTAGFilter(m.get.group("before")) + "<" + elem + " " + m.get.group("attributes") + ">" +
                                  htmlTAGFilter(m.get.group("following"))
 
                }
         case NORMALIZE(tmp) =>
-               val p = new Regex(
-                               s"""(?i)^(.*?)<${elem}(.*?)>(.+?)${endTag}(.*?)$$""",
+               val p = s"""(?i)^(.*?)<${elem}(.*?)>(.+?)${endTag}(.*?)$$""".r(
                                "before","attribute","inTAG","following")
                val m = p findFirstMatchIn(doc)
                if(m != None){
                        log debug "[" + elem + "]"
+                       log info "in TAGFilter NORMALIZE " + (System.currentTimeMillis() - start) + " msec"
                        return htmlTAGFilter(m.get.group("before")) +
                                        "<" + elem + m.get.group("attribute") + ">" +
                                        HTMLTag(elem)._2(m.get.group("inTAG")) + endTag +
                                        htmlTAGFilter(m.get.group("following"))
                }
         case NORMALIZE("---") =>
-               val p = new Regex("""^(.*?)$$""","plain")
+               val p = """^(.*?)$$""".r("plain")
                val m = p findFirstMatchIn(doc)
-               if(m != None){return node.toHTML(HTMLTag(elem)._2(m.get.group("plain"))).toString}
-        case _ => return specialCharConvert(doc)
+               if(m != None){
+                 log info "in TAGFilter NORMALIZE --- " + (System.currentTimeMillis() - start) + " msec"
+                 return node.toHTML(HTMLTag(elem)._2(m.get.group("plain"))).toString
+               }
+        case _ => return doc
         //case NORMALIZE("""\\/>""") =>
         //     log info "###"
        }
       }
     }
-    specialCharConvert(doc)
+
+    return doc
 
   }
 
index b8a5855..2702fe3 100644 (file)
@@ -92,7 +92,8 @@ object BlackQuill{
 
   def main(args:Array[String]){
     val sufRegex = """(\.md$)|(\.markdown$)|(\.txt$)|(\.bq$)|(\.blackquill$)""".r
-
+    val start = System.currentTimeMillis()
+    
     try{
       val it = args.iterator
       for(elem <- it){
@@ -117,20 +118,26 @@ object BlackQuill{
     }catch{ case e:Exception => log.warn("wrong switch is found see --help or Website\n" + wiki)}
     val fileHandler = FileIO
     // - fileHandler.openMarkdownFromString(str:String)
+    log info "prepared " + (System.currentTimeMillis() - start) + " msec"
     val text:List[String] = fileHandler openMarkdownFromFile(Switches.getInputfile)
-    val output = blackquill(text)
+    val output = blackquill(new HTMLMap().specialCharConvert(text))
+    log info "generate HTML " + (System.currentTimeMillis() - start) + " msec"
     Switches.outputFile = sufRegex.replaceAllIn(Switches.getInputfile,".html")
     val out = new PrintWriter(Switches.dirName + Switches.outputFile)
     //log info output
     output.foreach(out.print(_))
     out.close
+    log info (System.currentTimeMillis() - start) + " msec"
   }
 
   def blackquill(lines:List[String]):List[String] = {
+    val start = System.currentTimeMillis()
     val str = new HTMLMap htmlTAGFilter lines.mkString("""\,""")
-    log info str
+    log info "TAGFiltered " + (System.currentTimeMillis() - start) + " msec"
+    log debug str
     val HTML = new BQParser toHTML(str)
-    log info HTML
+    log info "toHTML " + (System.currentTimeMillis() - start) + " msec"
+    log debug HTML
     if(Switches.getStdout){
       println(HTML)
     }