Can somebody help me to convert markdown to html using python language.
I'm not a programmer but i want to understand some basic things in programming, and now i'm trying to make this conversion.
Can somebody show me for example how to convert this:
https://gist.githubusercontent.com/Irene26/6da8be01b46f07bf2a48/raw/6ef8e49a7c50e0aa1ae7465f6069f0a262b0ad84/gistfile1.txt
to look like this:
I'll be very thankfull if somebody will help me to understand this thing.
I was trying to do something like this. But i think it's not a good idea.
import os
import sys
import fileinput
searchquery = '#'
searchquery2 = '##'
searchquery3 = '######'
prefix = '<h1>'
suffix = '</h1>'
prefix2 = '<h2>'
suffix2 = '</h2>'
prefix3 = '<h6>'
suffix3 = '</h6>'
paragraph1 = '<p>'
paragraph2 = '</p>'
with open('file.txt') as f1:
with open('file2.txt', 'a') as f2:
lines = f1.readlines()
for i, line in enumerate(lines):
if i == 0:
if line.startswith(searchquery3):
line.replace("######", "")
f2.write('%s%s%s' % (prefix3, line[7:].rstrip('\n'), suffix3))
elif line.startswith(searchquery2):
line.replace("##", "")
f2.write('%s%s%s' % (prefix2, line[3:].rstrip('\n'), suffix2))
elif line.startswith(searchquery):
line.replace("#", "")
f2.write('%s%s%s' % (prefix, line[2:].rstrip('\n'), suffix))
if i > 0:
if line.startswith(searchquery3):
line.replace("######", "")
f2.write('\n\n%s%s%s' % (prefix3, line[7:].rstrip('\n'), suffix3))
elif line.startswith(searchquery2):
line.replace("##", "")
f2.write('\n\n%s%s%s' % (prefix2, line[3:].rstrip('\n'), suffix2))
elif line.startswith(searchquery):
line.replace("#", "")
f2.write('\n\n%s%s%s\n' % (prefix, line[2:].rstrip('\n'), suffix))
if not line.startswith('#') and line not in ['\n', '\r\n']:
f2.write('\n\n%s%s%s' % (paragraph1, line.rstrip('\n'), paragraph2))