def get_format(element, wikidict, tag): formats = [] if element not in wikidict.keys(): return ['', ''] else: element_classes = wikidict[element].keys() if 'noclass' in element_classes: formats.append(wikidict[element]['noclass']) elif 'default' in element_classes or 'append' in element_classes: classes = get_class(tag) if 'append' in element_classes: formats.append(wikidict[element]['append']) if 'default' in element_classes and classes is None: formats.append(wikidict[element]['default']) if classes is not None: for class_name in get_class(tag): if class_name in element_classes: formats.append(wikidict[element][class_name]) else: tag_classes = get_class(tag) for class_name in tag_classes: if class_name in element_classes: formats.append(wikidict[element][class_name]) if element == 'table': for attribute in get_attributes(tag): if attribute[0] == 'class': 1 #formats.append(wikidict[element][class_name]) else: formats.append( [' ' + attribute[0] + '="' + attribute[1] + '"', '']) if element == 'a': for attribute in get_attributes(tag): # bookmarks start with '#' and we don't want that obviously if attribute[0] == 'href': if attribute[1][0] == '#': return ['', ''] else: formats.append([attribute[1] + ' ', '']) format_before = '' format_after = '' for format_list in formats: if len(format_list) == 2: format_before += format_list[0] format_after = format_list[1] + format_after else: return format_list[0] return [format_before, format_after]
def get_format(element, wikidict, tag): formats = [] if element not in wikidict.keys(): return ["", ""] else: element_classes = wikidict[element].keys() if "noclass" in element_classes: formats.append(wikidict[element]["noclass"]) elif "default" in element_classes or "append" in element_classes: classes = get_class(tag) if "append" in element_classes: formats.append(wikidict[element]["append"]) if "default" in element_classes and classes is None: formats.append(wikidict[element]["default"]) if classes is not None: for class_name in get_class(tag): if class_name in element_classes: formats.append(wikidict[element][class_name]) else: tag_classes = get_class(tag) for class_name in tag_classes: if class_name in element_classes: formats.append(wikidict[element][class_name]) if element == "table": for attribute in get_attributes(tag): if attribute[0] == "class": 1 # formats.append(wikidict[element][class_name]) else: formats.append([" " + attribute[0] + '="' + attribute[1] + '"', ""]) if element == "a": for attribute in get_attributes(tag): # bookmarks start with '#' and we don't want that obviously if attribute[0] == "href": if attribute[1][0] == "#": return ["", ""] else: formats.append([attribute[1] + " ", ""]) format_before = "" format_after = "" for format_list in formats: if len(format_list) == 2: format_before += format_list[0] format_after = format_list[1] + format_after else: return format_list[0] return [format_before, format_after]
def wikicode(line, wikidict, stack, start, end): parent_match = stack[-1] # currently the last opening tag parent = getAttribute(parent_match) wikiline = '' i = -1; while parent not in wikidict.keys(): i = i - 1; if -i >= len(stack): return "" parent_match = stack[i] parent = getAttribute(parent_match) format = ['', ''] if parent in wikidict: if 'noclass' in wikidict[parent].keys(): format = wikidict[parent]['noclass'] else: classes = getClass(line, parent_match) for class_name in classes: # Lol now the serious business would be combining a list with bold text, ouch (still not implemented) if class_name in wikidict[parent].keys(): format = wikidict[parent][class_name] return (format[0] + line[start:end] + format[1]) return line[start:end]