Skip to content

Instantly share code, notes, and snippets.

@singh1114
Last active August 22, 2017 20:24
Show Gist options
  • Save singh1114/3397104e462ef70ef7af42d51ec73254 to your computer and use it in GitHub Desktop.
Save singh1114/3397104e462ef70ef7af42d51ec73254 to your computer and use it in GitHub Desktop.
Python script to allow put background into the HTML created using `pandoc`
import sys
# Read the second command line argument as the file name
read_file = open(sys.argv[1], 'r')
# Read the third command line argument as the output file name
write_file = open(sys.argv[2], 'w')
temp = ''
flag = 0
temp_two = ''
temp_three = ''
flag_two = 0
for line in read_file:
if flag_two is 2:
if '<section ' in line:
for word in line.split():
if not '>' in word:
temp_three = temp_three + word + ' '
else:
temp_four = word.replace('>', '')
temp_three = temp_three + temp_four + ' ' + temp_two + '>'
write_file.write(temp_three)
temp_three = ''
temp_two = ''
flag = 0
flag_two = 0
elif '</section>' in line:
pass
# when we encounter `<section` tag we need to start saving lines into variables
elif flag is 1 or '<section ' in line:
if '<!-- .slide' in line:
for word in line.split():
if 'data-background' in word:
temp_two = temp_two + word
flag_two = 2
elif '</section>' in line:
flag = 0
temp = temp + line
write_file.write(temp)
temp = ''
temp = temp + line
flag = 1
elif flag is 0:
write_file.write(line)
@singh1114
Copy link
Author

Usage

First, create the HTML using pandoc

$ pandoc -s --mathjax -i -t revealjs input_file.md -o first_output_file.html

Now use the following code as follows:

$ python background.py first_output_file.html final_output_file.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment