[DEV] add code parsing and display for ducumentation

This commit is contained in:
Edouard DUPIN 2013-12-10 21:36:03 +01:00
parent 47b884d9b2
commit b02c8b5221
15 changed files with 244 additions and 10 deletions

View File

@ -2,6 +2,7 @@
import lutinDebug as debug
import sys
import lutinTools
import codeHL
import re
@ -18,7 +19,7 @@ import re
def transcode(value):
#value = re.sub(r'\[code(( |\t|\n|\r)+style=(.*))?\](.*?)\[/code\]',
value = re.sub(r'\[code(( |\t|\n|\r)+style=(.*?))?\](.*?)\[/code\]',
r'<pre>\4</pre>',
replace_code, #r'<pre>\4</pre>',
value,
flags=re.DOTALL)
@ -26,3 +27,11 @@ def transcode(value):
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>'

View File

@ -31,6 +31,19 @@ def transcode(value):
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)
@ -51,3 +64,14 @@ def replace_link(match):
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

@ -22,6 +22,7 @@ import re
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'\[b\](.*?)\[/b\]',
r'<span style="font-weight: bold;">\1</span>',
value,

View File

@ -7,6 +7,7 @@ import re
##
## @brief Transcode .
## =?=Page Title=?=
## ==Title 1==
## ===Title 2===
## ====Title 3====
@ -17,6 +18,10 @@ import re
##
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)
@ -36,7 +41,8 @@ def transcode(value):
value = re.sub(r'\n==(.*?)==',
r'\n<h1>\1</h1>',
'\n' + value)
# todo : remove \n at the start of the file ...
value = value[1:]
return value

View File

@ -2,6 +2,7 @@
import lutinDebug as debug
import sys
import lutinTools
import re
import BB_Title
import BB_Text
import BB_IndentAndDot
@ -20,6 +21,9 @@ import BB_Specification
## @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)

View File

@ -2,3 +2,30 @@
import lutinDebug as debug
import sys
import lutinTools
import codeHLcpp
import codeHLBBcode
import codeHLJava
import codeHLjson
import codeHLPython
import codeHLXML
import codeHLshell
def transcode(type, value):
if type == "c++":
value = codeHLcpp.transcode(value)
elif type == "java":
value = codeHLJava.transcode(value)
elif type == "bbcode":
value = codeHLBBcode.transcode(value)
elif type == "python":
value = codeHLPython.transcode(value)
elif type == "json":
value = codeHLjson.transcode(value)
elif type == "xml":
value = codeHLXML.transcode(value)
elif type == "shell":
value = codeHLshell.transcode(value)
return value

View File

@ -2,3 +2,8 @@
import lutinDebug as debug
import sys
import lutinTools
import re
def transcode(value):
return value

View File

@ -2,3 +2,8 @@
import lutinDebug as debug
import sys
import lutinTools
import re
def transcode(value):
return value

View File

@ -2,3 +2,8 @@
import lutinDebug as debug
import sys
import lutinTools
import re
def transcode(value):
return value

View File

@ -2,3 +2,8 @@
import lutinDebug as debug
import sys
import lutinTools
import re
def transcode(value):
return value

View File

@ -2,3 +2,62 @@
import lutinDebug as debug
import sys
import lutinTools
import re
listRegExp = [
[ r'/\*\*(.*?)\*/', 'code-doxygen'],
[ r'/\*(.*?)\*/', 'code-comment'],
[ r'//!(.*?)\n', 'code-doxygen'],
[ r'//(.*?)\n', 'code-comment'],
[ r'#(.*?)\n', 'code-preproc'],
[ r'"((\\"|.)*?)"', 'code-text-quote'],
[ r"'(('|.)*?)'", 'code-text-quote'],
[ r'(inline|const|class|virtual|private|public|protected|friend|const|extern|auto|register|static|volatile|typedef|struct|union|enum)',
'code-storage-keyword'],
[ r'(bool|BOOL|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128))',
'code-type'],
[ r'(((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?)',
'code-number'],
[ r'(m_[A-Za-z_0-9])',
'code-member'],
[ r'(( |\t)_[A-Za-z_0-9]*)',
'code-input-function'],
[ r'(return|goto|if|else|case|default|switch|break|continue|while|do|for|sizeof)( |\t|\(|\{)',
'code-keyword'],
[ r'((new|delete|try|catch|memset|fopen|fread|fwrite|fgets|fclose|printf|(f|s|diag_)printf|calloc|malloc|realloc|(cyg|sup)_([a-z]|[A-Z]|[0-9]|_)+)( |\t|\())',
'code-function-system'],
[ r'((\w|_)+[ \t]*\()',
'code-function-name'],
[ r'(NULL|MAX|MIN|__LINE__|__DATA__|__FILE__|__func__|__TIME__|__STDC__)',
'code-generic-define'],
[ r'([A-Z_][A-Z_0-9]{3,500})',
'code-macro"'],
[ r'(==|>=|<=|!=|>{1,2}|<{1,2}|&&|\{|\})',
'code-operator'],
[ r'(true|TRUE|false|FALSE)',
'<code-operator'],
[ r'((\w+::)+\w+)',
'code-class']
]
def transcode(value):
inValue = value
outValue = ""
haveFindSomething = False;
for reg1, color in listRegExp:
result = re.search(reg1, inValue, re.DOTALL)
while result != None:
haveFindSomething = True
# sub parse the start :
outValue += transcode(inValue[:result.start()])
# transform local
outValue += '<span class="' + color + '">'
outValue += result.group()
outValue += '</span>'
# change the input value
inValue = inValue[result.end():]
# Search again ...
result = re.search(reg1, inValue, re.DOTALL)
outValue += inValue
return outValue

View File

@ -2,3 +2,9 @@
import lutinDebug as debug
import sys
import lutinTools
import re
def transcode(value):
return value

14
codeHL/codeHLshell.py Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/python
import lutinDebug as debug
import sys
import lutinTools
import re
listRegExp = [
[ r'#(.*?)\n', r'<span class="code-preproc">#\1</span>\n']
]
def transcode(value):
for reg1, reg2 in listRegExp:
value = re.sub(reg1, reg2, value, flags=re.DOTALL)
return value

View File

@ -6,6 +6,7 @@ import lutinTools
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/ply/ply/")
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/cppParser/CppHeaderParser/")
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/codeBB/")
sys.path.append(lutinTools.GetCurrentPath(__file__) + "/codeHL/")
import CppHeaderParser
import lutinDocHtml
import lutinDocMd

View File

@ -129,3 +129,66 @@ pre {
text-decoration:none;
color:#466cb4;
}
.code-doxygen {
text-decoration:none;
color:#bf3e00;
font-weight:bold;
}
.code-comment {
text-decoration:none;
color:#b704b5;
}
.code-preproc {
text-decoration:none;
color:#ac0000;
}
.code-text-quote {
text-decoration:none;
color:#008e00;
}
.code-number {
text-decoration:none;
color:#007b00;
}
.code-member {
text-decoration:none;
color:#7c5406;
}
.code-input-function {
text-decoration:none;
color:#B80000;
font-weight:bold;
}
.code-function-name {
text-decoration:none;
color:#09857e;
font-weight:bold;
}
.code-function-system {
text-decoration:none;
color:#acaa00;
}
.code-generic-define {
text-decoration:none;
color:#3c850b;
}
.code-macro {
text-decoration:none;
color:#3c850b;
}
.code-operator {
text-decoration:none;
color:#1633a3;
}
.code-keyword {
text-decoration:none;
color:#466cb4;
}
.code-class {
text-decoration:none;
color:#006cb4;
}