Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 40 lines (31 sloc) 1.17 KB
#!/usr/bin/env python
import re
import sys
in_file = sys.argv[1]
out_file = sys.argv[1]
with open(in_file, 'r') as f:
content =
def code_to_markdown(content):
def repl(m):
return '\n'.join([' ' + line for line in'\n')])
return re.sub(re.compile('<pre.*?>(.*?)</pre>', re.MULTILINE|re.DOTALL), repl, content)
def fix_img_tags(content):
def repl(m):
# replaces img locations
m ='', '/media/wp-content/')
# remove width & height
m = re.sub(r'(width|height)="\d+"', '', m)
return m
return re.sub(re.compile('(<img.*?/>)', re.MULTILINE|re.DOTALL), repl, content)
def github_to_gitlab(content):
return content.replace(':', ':')
def remove_layout_post(content):
return re.sub(r'layout:\spost\n', '', content)
# Commented out to prevent accidentally wrecking havoc on already converted content
# content = code_to_markdown(content)
# content = fix_img_tags(content)
# content = github_to_gitlab(content)
# content = remove_layout_post(content)
# with open(out_file, 'w') as f:
# f.write(content)