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])
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")
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)
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")
}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)
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
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")
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){
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))
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){
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")
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")
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] = {
}
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")
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){
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
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")
}
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)
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)
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">«</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")
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("|")){
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")
val headList = heads.toList
if(headList.size != alignList.size){
log error "Table header is wrong.:" + headList
- exit(-1)
+ exit()
}
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")
}
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")
}
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")
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)
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)
}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{
_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
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
}
- private def urlDefinitions(doc:String):String = {
+ def urlDefinitions(doc:String):String = {
def _urlDefinitions(text:String):String = {
var bef = ""
var fol = ""
_urlDefinitions(doc)
}
- private def decideClassOrStyle(doc:String,className:String):String = {
+ def decideClassOrStyle(doc:String,className:String):String = {
if(className == "" || className == null){
return ""
}
}
}
- private def getTitleName(title:String):String = {
+ def getTitleName(title:String):String = {
if(title == ""| title == null){
return ""
}
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 = ""
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
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) +
doc
}
- private def ltgtExpand(doc:String):String = {
+ def ltgtExpand(doc:String):String = {
return doc.replaceAll("&","&").replaceAll("<",">").replaceAll(">",">")
}
- 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 = ""
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 = ""
}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 = ""
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){
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 = ""
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
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 = {
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 = {
return bef
}
-}
\ No newline at end of file
+}
"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(
"""~=""".r -> "≅","""<\_""".r -> "≤",""">\_""".r -> "&ge","""\|FA""".r -> "∀","""\|EX""".r -> "∃",
"""\|=""".r -> "≡","""\(\+\)""".r -> "⊕","""\(\-\)""".r -> "⊖","""\(X\)""".r -> "⊗",
"""\(c\)""".r -> "©","""\(R\)""".r ->"®","""\(SS\)""".r -> "§","""\(TM\)""".r -> "™",
- """!in""".r -> "∉", """\\<""".r->"<","""\\>""".r->">","""\\&""".r->"&")
+ """!in""".r -> "∉", """\\<""".r->"<","""\\>""".r->">","""\\&""".r->"&","""/\*""".r ->"/∗","""\*/""".r -> "∗/")
private def passThrough(text:String):String = {text}
}
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 = {
}
*/
- 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
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
}