auth.wiki(render='html')
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.0.8 (2012-09-08 21:59:44) stable
|
Version 2.0.8 (2012-09-08 22:22:02) stable
|
||||||
|
|||||||
@@ -559,6 +559,29 @@ def markmin_escape(text):
|
|||||||
return regex_markmin_escape.sub(
|
return regex_markmin_escape.sub(
|
||||||
lambda m: '\\'+m.group(0).replace('\\','\\\\'), text)
|
lambda m: '\\'+m.group(0).replace('\\','\\\\'), text)
|
||||||
|
|
||||||
|
def replace_autolinks(text,autolinks):
|
||||||
|
return regex_auto.sub(lambda m: autolinks(m.group('k')), text)
|
||||||
|
|
||||||
|
def replace_at_urls(text,url):
|
||||||
|
# this is experimental @{function/args}
|
||||||
|
# turns into a digitally signed URL
|
||||||
|
def u1(match,url=url):
|
||||||
|
a,c,f,args = match.group('a','c','f','args')
|
||||||
|
return url(a=a or None,c=c or None,f = f or None,
|
||||||
|
args=args.split('/'), scheme=True, host=True)
|
||||||
|
return regex_URL.sub(u1,text)
|
||||||
|
|
||||||
|
def replace_components(text,env):
|
||||||
|
def u2(match, env=env):
|
||||||
|
f = env.get(match.group('a'), match.group(0))
|
||||||
|
if callable(f):
|
||||||
|
try:
|
||||||
|
f = f(match.group('b'))
|
||||||
|
except Exception, e:
|
||||||
|
f = 'ERROR: %s' % e
|
||||||
|
return str(f)
|
||||||
|
return regex_env.sub(u2, text)
|
||||||
|
|
||||||
def autolinks_simple(url):
|
def autolinks_simple(url):
|
||||||
"""
|
"""
|
||||||
it automatically converts the url to link,
|
it automatically converts the url to link,
|
||||||
@@ -829,13 +852,7 @@ def render(text,
|
|||||||
text = regex_backslash.sub(lambda m: m.group(1).translate(ttab_in), text)
|
text = regex_backslash.sub(lambda m: m.group(1).translate(ttab_in), text)
|
||||||
|
|
||||||
if URL is not None:
|
if URL is not None:
|
||||||
# this is experimental @{function/args}
|
text = replace_at_urls(text,URL)
|
||||||
# turns into a digitally signed URL
|
|
||||||
def u1(match,URL=URL):
|
|
||||||
a,c,f,args = match.group('a','c','f','args')
|
|
||||||
return URL(a=a or None,c=c or None,f = f or None,
|
|
||||||
args=args.split('/'), scheme=True, host=True)
|
|
||||||
text = regex_URL.sub(u1,text)
|
|
||||||
|
|
||||||
if latex == 'google':
|
if latex == 'google':
|
||||||
text = regex_dd.sub('``\g<latex>``:latex ', text)
|
text = regex_dd.sub('``\g<latex>``:latex ', text)
|
||||||
@@ -878,7 +895,7 @@ def render(text,
|
|||||||
text = regex_proto.sub(lambda m: protolinks(*m.group('p','k')), text)
|
text = regex_proto.sub(lambda m: protolinks(*m.group('p','k')), text)
|
||||||
|
|
||||||
if autolinks:
|
if autolinks:
|
||||||
text = regex_auto.sub(lambda m: autolinks(m.group('k')), text)
|
text = replace_autolinks(text,lambda m: autolinks(m.group('k')))
|
||||||
|
|
||||||
#############################################################
|
#############################################################
|
||||||
# normalize spaces
|
# normalize spaces
|
||||||
@@ -1304,15 +1321,7 @@ def render(text,
|
|||||||
text = regex_expand_meta.sub(expand_meta, text)
|
text = regex_expand_meta.sub(expand_meta, text)
|
||||||
|
|
||||||
if environment:
|
if environment:
|
||||||
def u2(match, environment=environment):
|
text = replace_components(text,environment)
|
||||||
f = environment.get(match.group('a'), match.group(0))
|
|
||||||
if callable(f):
|
|
||||||
try:
|
|
||||||
f = f(match.group('b'))
|
|
||||||
except Exception, e:
|
|
||||||
f = 'ERROR: %s' % e
|
|
||||||
return str(f)
|
|
||||||
text = regex_env.sub(u2, text)
|
|
||||||
|
|
||||||
return text.translate(ttab_out)
|
return text.translate(ttab_out)
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ from utils import web2py_uuid
|
|||||||
from fileutils import read_file, check_credentials
|
from fileutils import read_file, check_credentials
|
||||||
from gluon import *
|
from gluon import *
|
||||||
from gluon.contrib.autolinks import expand_one
|
from gluon.contrib.autolinks import expand_one
|
||||||
|
from gluon.contrib.markmin.markmin2html import \
|
||||||
|
replace_at_urls, replace_autolinks, replace_components
|
||||||
from gluon.dal import Row
|
from gluon.dal import Row
|
||||||
|
|
||||||
import serializers
|
import serializers
|
||||||
@@ -4486,6 +4488,15 @@ class Wiki(object):
|
|||||||
*[A(t.strip(),_href=URL(args='_search',vars=dict(q=t)))
|
*[A(t.strip(),_href=URL(args='_search',vars=dict(q=t)))
|
||||||
for t in page.tags or [] if t.strip()]).xml()
|
for t in page.tags or [] if t.strip()]).xml()
|
||||||
return html
|
return html
|
||||||
|
def html_render(self,page):
|
||||||
|
html = page.body
|
||||||
|
# @///function -> http://..../function
|
||||||
|
html = replace_at_urls(html,URL)
|
||||||
|
# http://...jpg -> <img src="http://...jpg/> or oembed
|
||||||
|
html = replace_autolinks(html,lambda link: expand_one(link,{}))
|
||||||
|
# @{component:name} -> <script>embed component name</script>
|
||||||
|
html = replace_components(html,self.env)
|
||||||
|
return html
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def component(text):
|
def component(text):
|
||||||
"""
|
"""
|
||||||
@@ -4500,6 +4511,7 @@ class Wiki(object):
|
|||||||
self.env = env or {}
|
self.env = env or {}
|
||||||
self.env['component'] = Wiki.component
|
self.env['component'] = Wiki.component
|
||||||
if render == 'markmin': render=self.markmin_render
|
if render == 'markmin': render=self.markmin_render
|
||||||
|
elif render == 'html': render=self.html_render
|
||||||
self.auth = auth
|
self.auth = auth
|
||||||
if self.auth.user:
|
if self.auth.user:
|
||||||
self.force_prefix = force_prefix % self.auth.user
|
self.force_prefix = force_prefix % self.auth.user
|
||||||
|
|||||||
Reference in New Issue
Block a user