#!/usr/bin/env python3 import sys import traceback def ignorePHP(): global newCode global position phpCodeUsed = 'true' while ((code[position] != '?' or code[position] != '%') and code[position+1] != '>'): newCode += code[position] position += 1 newCode += code[position] position += 1 def ignoreScripts(): global newCode global position while (code[position] + code[position+1] + code[position+2] + code[position+3] + code[position+4] + code[position+5] + code[position+6] + code[position+7] + code[position+8] != ''): #Turns out even if it's in a string, HTML just says "fvck everything" when it comes to . newCode += code[position] position += 1 #"/script>" won't be checked by the parser so we can just let the code write itself. def ignoreComments(): global newCode global position while ((code[position] + code[position+1] + code[position+2]) != '-->'): newCode += code[position] position += 1 newCode += "-->" position += 2 def newUserAttribute(): global newCode global position endMarker = code[position] newCode += code[position] position += 1 while code[position] != endMarker: newCode += code[position] position += 1 newCode += code[position] position += 1 def newClass(): global newCode global position newCode += ' class="' position += 1 # Replace . with ' class="'. NOTE THE SPACE. When replacing classes, .s will ALWAYS be transformed into a space. .s cannot be used for IDs or classes. It's not valid CSS. while code[position] not in '#> ': # Keep checking until we hit a # (new id), a > (end of tag), or a space (undefined attribute) if code[position] == '.': #Special code to group classes together newCode += ' ' else: newCode += code[position] position += 1 newCode += '"' #And finish it off with the closing "! DO NOT ADD A SPACE since spaces are added before classes and ids already. Other spaces are user-defined. def newId(): #Thankfully for me, ids are much easier to replace than classes. global newCode global position newCode += ' id="' position += 1 while code[position] not in '#> .': newCode += code[position] position += 1 newCode += '"' def startReplacing(): global newCode global position scriptUsed = 'false' newCode += code[position] # Put in the <. position += 1 #Special escapes if code[position] == '?' or code[position] == '%': ignorePHP() elif (code[position] + code[position+1] + code[position+2]) == '!--': ignoreComments() else: if (code[position] + code[position+1] + code[position+2] + code[position+3] + code[position+4] + code[position+5]) == 'script': scriptUsed = 'true' #we're delaying this so we can still check for classes and IDs on the