#---------------------------------------------------------------------------- # Filename: layout.py # Revision: 0.1 # # Copyright 2008 Christopher Myers and Justin Davis # # "Table Element Shame Eliminator" # The purpose of this script is to transform markup with our magical "layout" # element into valid HTML using the html table. # # You have unlimited license to use this software however you want. There # is no warranty either expressed nor implied. Actually, we recommend not # using it. It just exists to prove a point. #---------------------------------------------------------------------------- import os import sys from BeautifulSoup import BeautifulSoup def usage(): print "Usage: %s input-filename" % (sys.argv[0]) if not sys.argv[1:] or not os.path.exists(sys.argv[1]) or \ not os.path.isfile(sys.argv[1]): usage() sys.exit(1) # Soup the input infile = sys.argv[1] fhandle = open(infile, "r") soup = BeautifulSoup(fhandle) fhandle.close() # Convert from our semantic elements to actual html elements layout_to_table_map = { "layout" : "table", "layout-row" : "tr", "layout-cell" : "td" } layout_elements = soup.findAll(layout_to_table_map.keys()) for layout_element in layout_elements: layout_element.name = layout_to_table_map[layout_element.name] print soup.prettify()