Skip to content

Instantly share code, notes, and snippets.

@durgaswaroop
Created December 31, 2017 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save durgaswaroop/dd9dcb1e592751c1aced5f0f42aeedc1 to your computer and use it in GitHub Desktop.
Save durgaswaroop/dd9dcb1e592751c1aced5f0f42aeedc1 to your computer and use it in GitHub Desktop.
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