Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modifications needed to be done on html generated by pandoc for blogger
import sys
import os
import fileinput
# alias modifications="python ~/Desktop/30DaysOfBlogging/modifications.py"
# Run the script with `modifications <markdown file>`
def modify(html_file):
# If file doesnot exist, just exit
if not os.path.exists(html_file):
print("ERROR: HTML file '" + html_file + "' does not exist. Exiting")
sys.exit()
full_file = open(html_file).read()
modified_file = full_file.replace('<pre><code>', '<pre class="prettyprint">').replace('</code></pre>', '</pre>')
with open(html_file, 'w') as file:
file.write(modified_file)
if __name__ == '__main__':
# One argument, which is the name of the html file
if len(sys.argv) is not 2:
print("ERROR: One and only one argument needed. Html file")
sys.exit()
html_file = sys.argv[1]
modify(html_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment