Eluna fix parser &links

This commit is contained in:
Rochet2
2014-08-11 20:58:08 +03:00
parent f71a820eba
commit 4e231b77ab

View File

@@ -90,42 +90,25 @@ if __name__ == '__main__':
method_names.append('&' + class_.name + ':' + method.name) method_names.append('&' + class_.name + ':' + method.name)
def link_parser(content): def link_parser(content):
# Split the content into small tokens. # Replace all occurrencies of &Class:Function and then &Class with a link to given func or class
tokens = content.split()
# The content will be reassembled from the parsed tokens.
content = ''
for token in tokens: for name in method_names:
# Ignore tokens that don't start with "&". # Take the "amp;" off the front of the method's name.
if not token.startswith('&'): full_name = name[len('&'):]
content += token + ' ' # Split "Class:Method" into "Class" and "Method".
continue class_name, method_name = full_name.split(':')
url = '{}{}/{}.html'.format(('../' * level), class_name, method_name)
# Replace occurrencies of &Class:Method with the url created
content = content.replace(name, '<a class="fn" href="{}">{}</a>'.format(url, full_name))
# Try to find a matching class. for name in class_names:
for class_name in class_names: # Take the "&amp;" off the front of the class's name.
if token.startswith(class_name): class_name = name[len('&amp;'):]
# Take the "&amp;" off the front of the token and class's name. url = '{}{}/index.html'.format(('../' * level), class_name)
token = token[len('&amp;'):] # Replace occurrencies of &Class:Method with the url created
class_name = class_name[len('&amp;'):] content = content.replace(name, '<a class="mod" href="{}">{}</a>'.format(url, class_name))
url = '{}{}/index.html'.format(('../' * level), class_name)
token = '<a class="mod" href="{}">{}</a>'.format(url, token)
break
# No matching class, try to find a method. return content
else:
for method_name in method_names:
if token.startswith(method_name):
# Take the "amp;" off the front of the token.
full_name = token[len('&amp;'):]
# Split "Class:Method" into "Class" and "Method".
class_name, method_name = method_name.split(':')
url = '{}{}/{}.html'.format(('../' * level), class_name, method_name)
token = '<a class="fn" href="{}">{}</a>'.format(url, full_name)
break
content += token + ' '
return content[:-1] # Strip off the last space.
# Links to the "Programming in Lua" documentation for each Lua type. # Links to the "Programming in Lua" documentation for each Lua type.
lua_type_documentation = { lua_type_documentation = {