I’m trying to create a custom syntax for my users to format some html
so a user can enter something like:
**some text here**
the some more text down here
**Another bunch of stuff**
then some other junk
and I get:
<h1>some text here</h2>
<p>the some more text down here</p>
<h1>Another bunch of stuff</h1>
<p>then some other junk</p>
and hopefully leave some room to make up other tags as I need them
edit:
So my question is how would I write the regex function to convert some given text and have it find every instance of an opening and closing ** and replace them with the appropriate or tags.
i have:
import re
header_pattern = re.compile(r'(?P**)(?P.*)(?P**)’, re.MULTILINE)
def format_headers(text):
def process_match(m):
return "<h2>%s</h2>" % m.group('header')
new_text = header_pattern.sub(process_match, text)
print new_text
but this only grabs the first ** and last ** and ignores ones in the middle.
Use some standard solution. Like Markdown. Its is most preferable.
To match your header strings use
r'\*\*(.*?)\*\*'. See example