Created
May 20, 2011 12:44
-
-
Save sbp/982821 to your computer and use it in GitHub Desktop.
Convert plain text files to hypertext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import sys | |
| name = sys.argv[1] | |
| print '<!DOCTYPE html>' | |
| print '<title>%s</title>' % name | |
| print '<meta charset="utf-8">' | |
| print '<link rel="stylesheet" href="style.css">' | |
| with open(name) as f: | |
| for line in f: | |
| line = line.rstrip('\r\n') | |
| line = line.replace('&', '&') | |
| line = line.replace('<', '<') | |
| if line.startswith(' '): | |
| a = len(line) | |
| line = line.lstrip(' ') | |
| line = (' ' * (len(line) - a)) + line | |
| print line + '<br>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment