"""
+
+def parse_markdown(string,parent=False,parent_quote=False,subquote=0): # PARSES A SINGLE LINE !
+ global liste
+ global ID
+ global headers
+ global quote
+ suffix=""
+ prefix=""
+ if string.find("*") != -1 and (string[0:string.find("*")].count(" ") == string.find("*")) and not (parent or string[string.find("*")+1]=="*"): # LISTS
+ prevliste=liste
+ liste=1+int(string.find("*")/3)
+ if (liste > prevliste):
+ for i in range(0,liste-prevliste):
+ prefix+="
"
+ elif (liste < prevliste):
+ for i in range(0,prevliste-liste):
+ prefix+="
"+suffix
+ if not parent and liste != 0 and string=="":
+ for i in range(0,liste):
+ prefix+=""
+ liste=0
+ if len(string) > 2 and string[0:2]=="> ":
+ curquote=1
+ string=string[2:]
+ while len(string) > 2 and string[0:2]=="> ":
+ string=string[2:]
+ curquote+=1
+ for i in range(quote,curquote):
+ prefix+='
'
+ for i in range(curquote,quote):
+ prefix+='
'
+ quote=curquote
+ return prefix+parse_markdown(string,parent_quote=True)
+ if not parent_quote and quote != 0:
+ for i in range(0,quote):
+ prefix+=""
+ quote=0
+ if (len(string)) == 0:
+ return prefix+" "
+ if len(string) > 3 and (string[0] == "*" or string[0] == "-" or string[0] == "_")and string.count(string[0])==len(string):
+ return prefix+""
+ if (string[-2:]==" "):
+ return prefix+parse_markdown(string[:-2],parent=True)+" "
+ if (string[0]=="#"):
+ space=string.find(" ")
+ c=string[0:space-1].count("#")
+ if space==-1 or string[space+1:].count(" ")==len(string)-space-1:
+ return " "
+ if (space-1==c):
+ ID+=1
+ c+=1
+ temp="'+parse_markdown(string[space+1:],parent=True)+""
+ headers.append((temp,str(ID)))
+ temp=prefix+temp[:3]+' id="gheader'+str(ID)+'"'+temp[3:]
+ return temp
+ bold=False
+ boldamount=string.count("**")//2*2
+ ba=0
+ italic=False
+ ia=0
+ italicamount=string.count("__")//2*2
+ code=False
+ link=False
+ link2=False
+ codeamount=string.count("`")//2*2
+ ca=0
+ startindex=0
+ tags=[]
+ currentstring=""
+ index=-1
+ while index in range(-1,len(string)-1):
+ index+=1
+ appendtag=False
+ c=string[index]
+ if c == "`":
+ if ca < codeamount:
+ code=not code
+ ca=ca+1
+ if not code: # We have just closed a code fragment
+ tags.append((string[startindex+1:index],"code"))
+ continue
+ else: # A new one starts : SAVE INDEX + SAVE CURRENT STRING !
+ appendtag=True
+ elif not code:
+ if c == "*" and len(string) > index+1 and string[index+1] == "*" and ba < boldamount and not italic:
+ index+=1
+ bold=not bold
+ ba=ba+1
+ if not bold: # We have just closed a code fragment
+ tags.append((string[startindex+1:index-1],"bold"))
+ continue
+ else: # A new one starts : SAVE INDEX + SAVE CURRENT STRING !
+ appendtag=True
+ elif c == "_" and len(string) > index+1 and string[index+1] == "_" and ia < italicamount and not bold:
+ index+=1
+ italic=not italic
+ ia=ia+1
+ if not italic: # We have just closed a code fragment
+ tags.append((string[startindex+1:index-1],"italic"))
+ continue
+ else: # A new one starts : SAVE INDEX + SAVE CURRENT STRING !
+ appendtag=True
+ elif c == "<" and not link:
+ appendtag=True
+ link=True
+ elif c == ">" and link:
+ link=False
+ tags.append((string[startindex+1:index],"link"))
+ continue
+ elif c == "!" and len(string) > index+1 and string[index+1] == "[":
+ breakit=False
+ text=""
+ index+=1
+ for i in range(index+2,len(string)-3):
+ c2=string[i]
+ if (c2 == "]"):
+ text=string[index+1:i]
+ if string[i+1]=="(":
+ for j in range(i+3,len(string)):
+ c3=string[j]
+ if (c3 == ")"):
+ breakit=True
+ imglink=string[i+2:j].split(" ",1)
+ tags.append((img(text,imglink[0],imglink[1]),"image"))
+ index=j+1
+ break
+ if breakit:
+ continue
+ elif c == "[":
+ breakit=False
+ text=""
+ for i in range(index+2,len(string)-3):
+ c2=string[i]
+ if (c2 == "]"):
+ text=string[index+1:i]
+ if string[i+1]=="(":
+ for j in range(i+3,len(string)):
+ c3=string[j]
+ if (c3 == ")"):
+ breakit=True
+ tags.append((text,"link",string[i+2:j]))
+ index=j+1
+ break
+ if breakit:
+ continue
+ if appendtag:
+ tags.append((currentstring,"normal"))
+ currentstring=""
+ startindex=index
+ continue
+ if not bold and not italic and not code and not link and not link2:
+ currentstring+=c
+ if len(currentstring) != 0:
+ tags.append((currentstring,"normal"))
+ result=""
+ for tag in tags:
+ string=tag[0]
+ p=""
+ s=""
+ wrap=False
+ if tag[1]=="code":
+ p,s="",""
+ elif tag[1]=="bold":
+ p,s="",""
+ wrap=True
+ elif tag[1]=="italic":
+ p,s="",""
+ wrap=True
+ elif tag[1]=="link":
+ if len(tag) == 2:
+ if tag[0][0:4] == "http": # CHECK LINKS !
+ p,s='',""
+ else:
+ p,s='',""
+ elif tag[1]=="image":
+ result+=tag[0]
+ continue
+ elif tag[1]=="italic":
+ p,s="",""
+ if wrap:
+ result+=p+parse_markdown(string,parent_quote=True,parent=True)+s
+ else:
+ result+=p+html_escape(string)+s
+ if parent_quote and parent:
+ return result
+ return prefix+"
"+result+"
"
+
+def parse_md(string): # Parse line by line
+ lines=string.split("\n")
+ ret=""
+ for i in range(len(lines)-1,0,-1): # Convert alternate header writings(underlines)
+ if abs(len(lines[i-1])-len(lines[i])) < 3 and len(lines[i]) > 0:
+ if lines[i].count("=")==len(lines[i]):
+ lines[i]=""
+ lines[i-1]="# "+lines[i-1]
+ elif lines[i].count("-")==len(lines[i]):
+ lines[i]=""
+ lines[i-1]="## "+lines[i-1]
+ i=0
+ ident=False
+ segments=0
+ for line in lines:
+ prefix=""
+ suffix=""
+ asteriskpos=line.find("*")
+ # or (len(line) > 1 and line[0]=="\t" and (asteriskpos==-1 or line[0:asteriskpos].count("\t") != asteriskpos)))
+ if liste== 0 and ((len(line) > 4 and line[0:4]==" "*4 and (asteriskpos==-1 or asteriskpos > 1 or line[0:asteriskpos].count(" ") != asteriskpos))):
+ if not ident:
+ prefix="
Magic-CTF is a new, magically themed CTF Engine & Game for Minetest Servers.
+
Minetest is a free software game engine currently under development to create various games based on voxel gameplay, inspired by InfiniMiner, Minecraft, and the like. Minetest was originally created by Perttu Ahola (alias “celeron55”).