[DEV] create the monk basic library

This commit is contained in:
2013-12-22 18:55:48 +01:00
commit b6c956edef
172 changed files with 23716 additions and 0 deletions

37
codeBB/BB_Code.py Normal file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import codeHL
import re
##
## @brief Transcode balise :
## [code language=cpp]
## int main(void) {
## return 0;
## }
## [/code]
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
#value = re.sub(r'\[code(( |\t|\n|\r)+style=(.*))?\](.*?)\[/code\]',
value = re.sub(r'\[code(( |\t|\n|\r)+style=(.*?))?\](.*?)\[/code\]',
replace_code, #r'<pre>\4</pre>',
value,
flags=re.DOTALL)
# TODO : remove the basic indentation of the element (to have a better display in the text tutorial ...
return value
def replace_code(match):
if match.group() == "":
return ""
#debug.info("plop: " + str(match.groups()))
value = codeHL.transcode(match.groups()[2], match.groups()[3])
return '<pre>' + value + '</pre>'

19
codeBB/BB_Image.py Normal file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode balise:
## [img w=125 h=45]dossier/image.jpg[/img]
## [img w=125 h=45]http://plop.com/dossier/image.png[/img]
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
return value

72
codeBB/BB_IndentAndDot.py Normal file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode
## commencez les ligne par ":" comme:
## : 1
## : 2
## ::2.1
## ::2.2
## :::2.2.1
## ::::2.2.1.1
## :::::2.2.1.1.1
## ::2.3
## :3
## resultat:
##
## 1
## 2
## 2.1
## 2.2
## 2.2.1
## 2.2.1.1
## 2.3
## 3
##
## note: lorsque vous sautez une ligne, la liste sarraite et en recommence une autre...
##
## Il est possible de mettre des ":" sans ligne appres ce qui genere une ligne vide..
##
## AND DOT
## **Ma ligne2 star consecutives engendrent des points quelque soit la position dans la ligne...
##
## Resultat:
##
## * premiere ligne
## * deusieme ligne
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'\n:',
r'\n:INDENT:',
value)
p = re.compile('((\:INDENT\:(.*?)\n)*)',
flags=re.DOTALL)
value = p.sub(replace_wiki_identation,
value)
value = re.sub(r'\*\*(.*?)\n',
r'<li>\1</li>',
value,
flags=re.DOTALL)
return value
def replace_wiki_identation(match):
if match.group() == "":
return ""
#debug.verbose("plop: " + str(match.group()))
value = "<ul>"
value += re.sub(r':INDENT:',
r'',
match.group())
value += "</ul>"
return transcode(value)

77
codeBB/BB_Link.py Normal file
View File

@@ -0,0 +1,77 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode:
## [http://votre_site.con] => http://votre_site.con
## [http://votre_site.con | text displayed] => text displayed
## [http://votre_site.con text displayed] => text displayed.
##
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
# named link : [[http://plop.html | link name]]
value = re.sub(r'\[\[http://(.*?) \| (.*?)\]\]',
r'<a href="http://\1">\2</a>',
value)
# direct link : [[http://plop.html]]
value = re.sub(r'\[\[http://(.*?)\]\]',
r'<a href="http://\1">http://\1</a>',
value)
# direct lib link : [lib[libname]]
value = re.sub(r'\[lib\[(.*?) \| (.*?)\]\]',
r'<a href="../\1">\2</a>',
value)
value = re.sub(r'\[doc\[(.*?) \| (.*?)\]\]',
r'<a href="\1.html">\2</a>',
value)
value = re.sub(r'\[tutorial\[(.*?) \| (.*?)\]\]',
r'<a href="tutorial_\1.html">\2</a>',
value)
value = re.sub(r'\[class\[(.*?)\]\]',
replace_link_class,
value)
"""
p = re.compile('\[\[(.*?)(|(.*?))\]\])',
flags=re.DOTALL)
value = p.sub(replace_link,
value)
"""
return value
"""
def replace_link(match):
if match.group() == "":
return ""
#debug.verbose("plop: " + str(match.group()))
value = "<ul>"
value += re.sub(r':INDENT:',
r'',
match.group())
value += "</ul>"
return transcode(value)
"""
def replace_link_class(match):
if match.group() == "":
return ""
#debug.info("plop: " + str(match.group()))
className = match.groups()[0]
value = re.sub(':', '_', className)
return '<a href="' + value + '.html">' + className + '</a>'

View File

@@ -0,0 +1,17 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode thales specification ...
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
return value

42
codeBB/BB_Table.py Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode table:
## { | tableau_type_1
## | [b]colone 1[/b]
## ligne 1
## | colone 2 ligne 1
## |---
## | colone 1 ligne 1
## | colone 2 ligne 2
## |}
## Avec autant de ligne et de colone que vous voullez..
## Il est possible de faire des retour a la ligne dans une case du tableau...
## En bref sa tend a marcher comme sur un Wiki...
##
## result:
## +-------------------------------------+
## | colone 1 |
## +------------------+------------------+
## | ligne 1 | colone 2 ligne 1 |
## +------------------+------------------+
## | colone 1 ligne 1 | colone 2 ligne 2 |
## +------------------+------------------+
##
## TODO : Create simple table like :
## | colone 1 ||
## | ligne 1 | colone 2 ligne 1 |
## | colone 1 ligne 1 | colone 2 ligne 2|
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
return value

91
codeBB/BB_Text.py Normal file
View File

@@ -0,0 +1,91 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode .
## [b]texte ici[/b]
## [i]texte ici[/i]
## [u]texte ici[/u]
## [strike]texte ici[/strike]
## [color=olive]texte ici[/color]
## [color=#456FF33F]texte ici[/color]
## Left : [left]texte ici[/left]
## Center : [center]texte ici[/center]
## Right : [right]texte ici[/right]
## [size=22]sdfgsdfgsdgsfd[/size]
## [cadre]mettre les code ici[/cadre]
## @param[in] string String to transform.
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'\[b\](.*?)\[/b\]',
r'<span style="font-weight: bold;">\1</span>',
value,
flags=re.DOTALL)
value = re.sub(r'\[i\](.*?)\[/i\]',
r'<span style="font-style: italic;">\1</span>',
value,
flags=re.DOTALL)
value = re.sub(r'\[u\](.*?)\[/u\]',
r'<span style="text-decoration: underline;">\1</span>',
value,
flags=re.DOTALL)
value = re.sub(r'\[sup\](.*?)\[/sup\]',
r'<sup>\1</sup>',
value,
flags=re.DOTALL)
value = re.sub(r'\[sub\](.*?)\[/sub\]',
r'<sub>\1</sub>',
value,
flags=re.DOTALL)
value = re.sub(r'\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]',
r'<span style="color: \1;">\2</span>',
value,
flags=re.DOTALL)
value = re.sub(r'\[center\](.*)\[/center\]',
r'<div align="center">\1</div>',
value,
flags=re.DOTALL)
value = re.sub(r'\[right\](.*?)\[/right\]',
r'<div align="right">\1</div>',
value,
flags=re.DOTALL)
value = re.sub(r'\[left\](.*?)\[/left\]',
r'<div align="left">\1</div>',
value,
flags=re.DOTALL)
value = re.sub(r'\[strike\](.*?)\[/strike\]',
r'<span><strike>\1</strike></span>',
value,
flags=re.DOTALL)
value = re.sub(r'\[size=(.*?)\](.*?)\[/size\]',
r'<span style="font-size: \1px; line-height: normal;">\2</span>',
value,
flags=re.DOTALL)
value = re.sub(r'\[cadre\](.*?)\[/cadre\]',
r'<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td class="quote">\1</td></tr></tbody></table>',
value,
flags=re.DOTALL)
value = re.sub(r'____(.*?)\n',
r'<hr>',
value,
flags=re.DOTALL)
return value

49
codeBB/BB_Title.py Normal file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode .
## =?=Page Title=?=
## ==Title 1==
## ===Title 2===
## ====Title 3====
## =====Title 4=====
## ======Title 5======
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'=\?=(.*?)=\?=',
r'<h1><center>\1</center></h1>',
value)
value = re.sub(r'\n======(.*?)======',
r'\n<h5>\1</h5>',
value)
value = re.sub(r'\n=====(.*?)=====',
r'\n<h4>\1</h4>',
value)
value = re.sub(r'\n====(.*?)====',
r'\n<h3>\1</h3>',
value)
value = re.sub(r'\n===(.*?)===',
r'\n<h2>\1</h2>',
value)
value = re.sub(r'\n==(.*?)==',
r'\n<h1>\1</h1>',
'\n' + value)
value = value[1:]
return value

27
codeBB/BB_comment.py Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode balise:
## /* ... */
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'\/\*(.*?)\*\/',
r'',
value,
flags=re.DOTALL)
"""
value = re.sub(r'\/\/(.*?)\n',
r'',
value)
"""
return value

30
codeBB/BB_lineReturn.py Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode balise:
## \n\n ==> <br/>
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'\r\n',
r'\n',
value)
value = re.sub(r'\n\n',
r'<br/>',
value)
value = re.sub(r'<br/>',
r'<br/>\n',
value)
return value

52
codeBB/codeBB.py Normal file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
import BB_Title
import BB_Text
import BB_IndentAndDot
import BB_Link
import BB_Image
import BB_Table
import BB_comment
import BB_lineReturn
import BB_Code
import BB_Specification
##
## @brief Transcode input data in the corect format.
## @param[in] string String to transform.
## @return Transformed string.
##
def transcode(value):
# remove html property
value = re.sub(r'<', r'&lt;', value)
value = re.sub(r'>', r'&gt;', value)
value = BB_comment.transcode(value)
value = BB_Title.transcode(value)
value = BB_Text.transcode(value)
value = BB_IndentAndDot.transcode(value)
value = BB_Link.transcode(value)
value = BB_Image.transcode(value)
value = BB_Table.transcode(value)
value = BB_Code.transcode(value)
value = BB_Specification.transcode(value)
value = BB_lineReturn.transcode(value)
return value
##
## @brief transcode a BBcode file in a html file
## @return True if the file is transformed
##
def transcode_file(inputFileName, outputFileName):
inData = monkTools.file_read_data(inputFileName)
if inData == "":
return False
outData = transcode(inData)
debug.warning(" out: " + outputFileName)
monkTools.file_write_data(outputFileName, outData)
return True