diff --git a/monk/codeMarkDown/MD_Code.py b/monk/codeMarkDown/MD_Code.py index 89eab2e..6b8b9e6 100644 --- a/monk/codeMarkDown/MD_Code.py +++ b/monk/codeMarkDown/MD_Code.py @@ -38,6 +38,8 @@ def transcode(value, _base_path): def transcode_part2(value): value = value.replace(":CODE:UNDER:SCORE:", "_") value = value.replace(":CODE:STAR:", "*") + value = value.replace(":CODE:BRACKET:START:", "[") + value = value.replace(":CODE:BRACKET:STOP:", "]") return value @@ -50,5 +52,7 @@ def replace_code(match): #value = value.replace("\n", "
") value = value.replace("_", ":CODE:UNDER:SCORE:") value = value.replace("*", ":CODE:STAR:") + value = value.replace("[", ":CODE:BRACKET:START:") + value = value.replace("]", ":CODE:BRACKET:STOP:") return '
' + str(value) + '
' diff --git a/monk/codeMarkDown/MD_Image.py b/monk/codeMarkDown/MD_Image.py index 0e00cd6..3d87565 100644 --- a/monk/codeMarkDown/MD_Image.py +++ b/monk/codeMarkDown/MD_Image.py @@ -3,6 +3,31 @@ from realog import debug import sys from monk import tools import re +import os + +image_base_path = "" + +def simplify_path(aaa): + #debug.warning("ploppppp " + str(aaa)) + st = [] + aaa = aaa.split("/") + for i in aaa: + if i == '..': + if len(st) > 0: + st.pop() + else: + continue + elif i == '.': + continue + elif i != '': + if len(st) > 0: + st.append("/" + str(i)) + else: + st.append(str(i)) + if len(st) == 1: + return "/" + #debug.error("ploppppp " + str(st)) + return "".join(st) ## @@ -13,9 +38,12 @@ import re ## @return Transformed string. ## def transcode(value, _base_path): + global image_base_path if len(_base_path) != 0: - base_path = (_base_path + '/').replace('/','__') + base_path = (_base_path + '/').replace('/',':IMAGE:UNDER:SCORE::IMAGE:UNDER:SCORE:') + image_base_path = _base_path else: + image_base_path = "" base_path = "" # named image : ![hover Value](http://sdfsdf.svg) value = re.sub(r'!\[http://(.*?)\][ \t]*\((.*?)\)', @@ -28,34 +56,82 @@ def transcode(value, _base_path): p = re.compile('!\[(.*?)\][ \t]*\((.*?)\)') value = p.sub(replace_image, value) - value = re.sub(r':BASE_PATH:', - r'' + base_path, - value) + #value = re.sub(r':BASE_PATH:', + # r'' + base_path, + # value) return value +def transcode_part2(value): + value = value.replace(":IMAGE:UNDER:SCORE:", "_") + value = value.replace(":IMAGE:STAR:", "*") + value = value.replace(":IMAGE:BRACKET:START:", "[") + value = value.replace(":IMAGE:BRACKET:STOP:", "]") + value = value.replace(":IMAGE:SLASH:", "/") + return value def replace_image(match): + global image_base_path if match.group() == "": return "" debug.verbose("Image parse: " + str(match.group())) - value = 'FalseImage: " + title + "
" + + if center == True: + value = "
" + value + "
" + elif right == True: + value = "" + value + "" + elif left == True: + value = "" + value + "" + return value + + diff --git a/monk/codeMarkDown/MD_Link.py b/monk/codeMarkDown/MD_Link.py index ee481f7..1834e46 100644 --- a/monk/codeMarkDown/MD_Link.py +++ b/monk/codeMarkDown/MD_Link.py @@ -44,6 +44,12 @@ def transcode(value, _base_path): return value +def transcode_part2(value): + value = value.replace(":LINK:UNDER:SCORE:", "_") + value = value.replace(":LINK:STAR:", "*") + value = value.replace(":LINK:BRACKET:START:", "[") + value = value.replace(":LINK:BRACKET:STOP:", "]") + return value def replace_link(match): global basic_link_path @@ -65,5 +71,9 @@ def replace_link(match): value += '.html">' + match.groups()[0] + '' else: value += '.html">' + match.groups()[1] + '' + value = value.replace("_", ":LINK:UNDER:SCORE:") + value = value.replace("*", ":LINK:STAR:") + value = value.replace("[", ":LINK:BRACKET:START:") + value = value.replace("]", ":LINK:BRACKET:STOP:") return value diff --git a/monk/codeMarkDown/MD_Table.py b/monk/codeMarkDown/MD_Table.py index 2642e4b..e04c58f 100644 --- a/monk/codeMarkDown/MD_Table.py +++ b/monk/codeMarkDown/MD_Table.py @@ -25,7 +25,7 @@ import re ## def transcode(value, _base_path): - p = re.compile('((\n\|(.*)\|)*)', + p = re.compile('(\n(\|[^\n\|]*)*\|)*', flags=re.DOTALL) value = p.sub(replace_table, value) @@ -38,7 +38,9 @@ def replace_table(match): table_index = 0 if match.group() == "": return "" - debug.warning("=============================: " + str(match.group())) + debug.warning("=============================: Parse TABLE ...") + debug.warning(str(match.group())) + debug.warning("=============================: ") value = '' value_global = re.sub(r'\n\|([\t -]*\|)+', r'', diff --git a/monk/codeMarkDown/MD_Title.py b/monk/codeMarkDown/MD_Title.py index b1f07a0..a585855 100644 --- a/monk/codeMarkDown/MD_Title.py +++ b/monk/codeMarkDown/MD_Title.py @@ -58,39 +58,48 @@ def transcode(value, _base_path): r'\n==Z==555==Z==\1', value) + """ value = re.sub(r'\n###### (.*?)(( |\t)*\{.*\})* ######', r'\n==Z==666==Z==\1', value) value = re.sub(r'\n###### (.*?)(( |\t)*\{.*\})*', r'\n==Z==666==Z==\1', value) + """ value = re.sub(r'\n##### (.*?)(( |\t)*\{.*\})* #####', - r'\n==Z==555==Z==\1', + r'\n==Z==666==Z==\1', value) - value = re.sub(r'\n##### (.*?)(( |\t)*\{.*\})*', - r'\n==Z==555==Z==\1', + value = re.sub(r'\n##### (.*?)(( |\t)*\{.*\})*\n', + r'\n==Z==666==Z==\1\n', value) value = re.sub(r'\n#### (.*?)(( |\t)*\{.*\})* ####', - r'\n==Z==444==Z==\1', + r'\n==Z==555==Z==\1', value) - value = re.sub(r'\n#### (.*?)(( |\t)*\{.*\})*', - r'\n==Z==444==Z==\1', + value = re.sub(r'\n#### (.*?)(( |\t)*\{.*\})*\n', + r'\n==Z==555==Z==\1\n', value) value = re.sub(r'\n### (.*?)(( |\t)*\{.*\})* ###', - r'\n==Z==333==Z==\1', + r'\n==Z==444==Z==\1', value) - value = re.sub(r'\n### (.*?)(( |\t)*\{.*\})*', - r'\n==Z==333==Z==\1', + value = re.sub(r'\n### (.*)(( |\t)*\{.*\})*\n', + r'\n==Z==444==Z==\1\n', value) value = re.sub(r'\n## (.*?)(( |\t)*\{.*\})* ##', - r'\n==Z==222==Z==\1', + r'\n==Z==333==Z==\1', value) - value = re.sub(r'\n## (.*?)(( |\t)*\{.*\})*', - r'\n==Z==222==Z==\1', + value = re.sub(r'\n## (.*?)(( |\t)*\{.*\})*\n', + r'\n==Z==333==Z==\1\n', + value) + + value = re.sub(r'\n# (.*?)(( |\t)*\{.*\})* #', + r'\n==Z==333==Z==\1', + value) + value = re.sub(r'\n# (.*?)(( |\t)*\{.*\})*\n', + r'\n==Z==333==Z==\1\n', value) value = re.sub(value_start, diff --git a/monk/codeMarkDown/__init__.py b/monk/codeMarkDown/__init__.py index f050028..1142bf7 100644 --- a/monk/codeMarkDown/__init__.py +++ b/monk/codeMarkDown/__init__.py @@ -37,18 +37,29 @@ def transcode(value, _base_path = ""): value = MD_Title.transcode(value, _base_path) value = MD_IndentAndDot.transcode(value, _base_path) value = MD_Code.transcode(value, _base_path) + + value = MD_Table.transcode(value, _base_path) value = MD_lineReturn.transcode(value, _base_path) value = MD_Title.transcode_clean_empty_line_after(value, _base_path) - value = MD_Text.transcode(value, _base_path) """ value = BB_Text.transcode(value, _base_path) value = BB_Specification.transcode(value, _base_path) """ - value = MD_Table.transcode(value, _base_path) value = MD_Image.transcode(value, _base_path) value = MD_Link.transcode(value, _base_path) value = MD_ResultSelection.transcode(value, _base_path) + + + + + value = MD_Text.transcode(value, _base_path) + + + + value = MD_Code.transcode_part2(value) + value = MD_Image.transcode_part2(value) + value = MD_Link.transcode_part2(value) return value ##