some markdown parsing.. jst for fun
This commit is contained in:
10
shop.py
10
shop.py
@@ -15,6 +15,8 @@ USERNAME = 'admin'
|
|||||||
PASSWORD = 'default'
|
PASSWORD = 'default'
|
||||||
URLFINDER = re.compile("((news|telnet|nttp|file|http|ftp|https)://[^ ]+)")
|
URLFINDER = re.compile("((news|telnet|nttp|file|http|ftp|https)://[^ ]+)")
|
||||||
URLPARSER = re.compile(r'(\[)([^\]]+)(\])\(([^\)]+)\)')
|
URLPARSER = re.compile(r'(\[)([^\]]+)(\])\(([^\)]+)\)')
|
||||||
|
BOLDFINDER = re.compile(r'\*([^\*]+)\*')
|
||||||
|
CODEFINDER = re.compile(r'\`([^\`]+)\`')
|
||||||
|
|
||||||
# create our little application :)
|
# create our little application :)
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@@ -99,6 +101,11 @@ def scan_for_new_documents(id):
|
|||||||
[shop, id])
|
[shop, id])
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
|
def markdown_parse(s):
|
||||||
|
s=BOLDFINDER.sub(r'*<span class="md_bold">\1</span>*',s)
|
||||||
|
s=CODEFINDER.sub(r'`<span class="md_code">\1</span>`',s)
|
||||||
|
return s
|
||||||
|
|
||||||
def urlify(s):
|
def urlify(s):
|
||||||
if URLPARSER.search(s):
|
if URLPARSER.search(s):
|
||||||
return URLPARSER.sub(r'[<a href="\4" target="_blank">\2</a>]',s)
|
return URLPARSER.sub(r'[<a href="\4" target="_blank">\2</a>]',s)
|
||||||
@@ -152,8 +159,11 @@ def show_shop(shopid):
|
|||||||
icon=u"\u2714"
|
icon=u"\u2714"
|
||||||
extra_class=""
|
extra_class=""
|
||||||
row=urlify(row).encode('ascii', 'xmlcharrefreplace')
|
row=urlify(row).encode('ascii', 'xmlcharrefreplace')
|
||||||
|
row=markdown_parse(row)
|
||||||
if row.startswith("#"):
|
if row.startswith("#"):
|
||||||
row="<span class=md_head>"+row+"</span>"
|
row="<span class=md_head>"+row+"</span>"
|
||||||
|
if row.startswith(">"):
|
||||||
|
row="<span class=md_quote>"+row+"</span>"
|
||||||
entries.append( dict(row=i, text=row, icon=icon, extra_class=extra_class) )
|
entries.append( dict(row=i, text=row, icon=icon, extra_class=extra_class) )
|
||||||
shared_to=[]
|
shared_to=[]
|
||||||
cur = g.db.execute('select * from shares')
|
cur = g.db.execute('select * from shares')
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ hr { border-color: #377ba8; }
|
|||||||
/* MD rendering */
|
/* MD rendering */
|
||||||
|
|
||||||
.md_head { color: #377ba8; font-weight: bold; }
|
.md_head { color: #377ba8; font-weight: bold; }
|
||||||
|
.md_quote { font-style: italic; }
|
||||||
|
.md_bold { font-weight: bold; }
|
||||||
|
.md_code { color: #a83737; }
|
||||||
|
|
||||||
/* dropdown */
|
/* dropdown */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user