[DEV] correct and better markdown decoration
This commit is contained in:
parent
04e7866da1
commit
4528de5235
@ -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", "<br/>")
|
||||
value = value.replace("_", ":CODE:UNDER:SCORE:")
|
||||
value = value.replace("*", ":CODE:STAR:")
|
||||
value = value.replace("[", ":CODE:BRACKET:START:")
|
||||
value = value.replace("]", ":CODE:BRACKET:STOP:")
|
||||
return '<pre>' + str(value) + '</pre>'
|
||||
|
||||
|
@ -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 = '<img src=":BASE_PATH:'
|
||||
value += match.groups()[1].replace("/", "__")
|
||||
#value = '<img src=":BASE_PATH:'
|
||||
value = '<img src="'
|
||||
value += simplify_path(os.path.join(image_base_path, match.groups()[1])).replace("/", "__")
|
||||
value += '" '
|
||||
|
||||
alt_properties = match.groups()[0].split("|")
|
||||
alt = False
|
||||
center = False
|
||||
right = False
|
||||
left = False
|
||||
showTitle = False
|
||||
title = False
|
||||
type = "Image"
|
||||
for elem in alt_properties:
|
||||
if alt == False:
|
||||
alt = True
|
||||
value += 'alt="' + elem + '" '
|
||||
title = elem
|
||||
continue
|
||||
key_alt, value_alt = elem.split("=")
|
||||
if key_alt == "width":
|
||||
value += 'width="' + value_alt + '" '
|
||||
elif key_alt == "height":
|
||||
value += 'height="' + value_alt + '" '
|
||||
if key_alt == "align":
|
||||
if value_alt == "center":
|
||||
center = True
|
||||
if value_alt == "right":
|
||||
right = True
|
||||
if value_alt == "left":
|
||||
left = True
|
||||
if key_alt == "type":
|
||||
type = value_alt
|
||||
if key_alt == "titleShow":
|
||||
if elem == "false":
|
||||
showTitle = False
|
||||
else:
|
||||
showTitle = True
|
||||
else:
|
||||
debug.warning("not manage element '" + key_alt + "' in '" + str(match.group()) + "'")
|
||||
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(":BASE:IMAGE:UNDER:SCORE:PATH:", ":BASE_PATH:")
|
||||
|
||||
if showTitle == True:
|
||||
value = "<br/>" + value + "<br/><u><b>Image: </b>" + title + "</u><br/>"
|
||||
|
||||
if center == True:
|
||||
value = "<center>" + value + "</center>"
|
||||
elif right == True:
|
||||
value = "<right>" + value + "</right>"
|
||||
elif left == True:
|
||||
value = "<left>" + value + "</left>"
|
||||
|
||||
return value
|
||||
|
||||
|
||||
|
@ -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] + '</a>'
|
||||
else:
|
||||
value += '.html">' + match.groups()[1] + '</a>'
|
||||
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
|
||||
|
||||
|
@ -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 = '<table class="doc_table">'
|
||||
value_global = re.sub(r'\n\|([\t -]*\|)+',
|
||||
r'',
|
||||
|
@ -58,39 +58,48 @@ def transcode(value, _base_path):
|
||||
r'\n==Z==555==Z==\1</h5>',
|
||||
value)
|
||||
|
||||
"""
|
||||
value = re.sub(r'\n###### (.*?)(( |\t)*\{.*\})* ######',
|
||||
r'\n==Z==666==Z==\1</h6>',
|
||||
value)
|
||||
value = re.sub(r'\n###### (.*?)(( |\t)*\{.*\})*',
|
||||
r'\n==Z==666==Z==\1</h6>',
|
||||
value)
|
||||
"""
|
||||
|
||||
value = re.sub(r'\n##### (.*?)(( |\t)*\{.*\})* #####',
|
||||
r'\n==Z==555==Z==\1</h5>',
|
||||
r'\n==Z==666==Z==\1</h5>',
|
||||
value)
|
||||
value = re.sub(r'\n##### (.*?)(( |\t)*\{.*\})*',
|
||||
r'\n==Z==555==Z==\1</h5>',
|
||||
value = re.sub(r'\n##### (.*?)(( |\t)*\{.*\})*\n',
|
||||
r'\n==Z==666==Z==\1</h5>\n',
|
||||
value)
|
||||
|
||||
value = re.sub(r'\n#### (.*?)(( |\t)*\{.*\})* ####',
|
||||
r'\n==Z==444==Z==\1</h4>',
|
||||
r'\n==Z==555==Z==\1</h4>',
|
||||
value)
|
||||
value = re.sub(r'\n#### (.*?)(( |\t)*\{.*\})*',
|
||||
r'\n==Z==444==Z==\1</h4>',
|
||||
value = re.sub(r'\n#### (.*?)(( |\t)*\{.*\})*\n',
|
||||
r'\n==Z==555==Z==\1</h4>\n',
|
||||
value)
|
||||
|
||||
value = re.sub(r'\n### (.*?)(( |\t)*\{.*\})* ###',
|
||||
r'\n==Z==333==Z==\1</h3>',
|
||||
r'\n==Z==444==Z==\1</h3>',
|
||||
value)
|
||||
value = re.sub(r'\n### (.*?)(( |\t)*\{.*\})*',
|
||||
r'\n==Z==333==Z==\1</h3>',
|
||||
value = re.sub(r'\n### (.*)(( |\t)*\{.*\})*\n',
|
||||
r'\n==Z==444==Z==\1</h3>\n',
|
||||
value)
|
||||
|
||||
value = re.sub(r'\n## (.*?)(( |\t)*\{.*\})* ##',
|
||||
r'\n==Z==222==Z==\1</h2>',
|
||||
r'\n==Z==333==Z==\1</h2>',
|
||||
value)
|
||||
value = re.sub(r'\n## (.*?)(( |\t)*\{.*\})*',
|
||||
r'\n==Z==222==Z==\1</h2>',
|
||||
value = re.sub(r'\n## (.*?)(( |\t)*\{.*\})*\n',
|
||||
r'\n==Z==333==Z==\1</h2>\n',
|
||||
value)
|
||||
|
||||
value = re.sub(r'\n# (.*?)(( |\t)*\{.*\})* #',
|
||||
r'\n==Z==333==Z==\1</h2>',
|
||||
value)
|
||||
value = re.sub(r'\n# (.*?)(( |\t)*\{.*\})*\n',
|
||||
r'\n==Z==333==Z==\1</h2>\n',
|
||||
value)
|
||||
|
||||
value = re.sub(value_start,
|
||||
|
@ -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
|
||||
|
||||
##
|
||||
|
Loading…
Reference in New Issue
Block a user