yet another markmin improvement, thanks Vladyslav

This commit is contained in:
mdipierro
2012-07-17 12:35:57 -05:00
parent f3ea2d1cc6
commit 598d979502
5 changed files with 26 additions and 29 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-07-17 10:59:23) dev
Version 2.00.0 (2012-07-17 12:35:54) dev
+2 -2
View File
@@ -50,8 +50,8 @@ def deletefile(arglist):
{{=button("#modules", T("modules"))}}
</span>
<span class="buttongroup">
{{=sp_button(URL('plugin',args=app), T("back"))}}
{{=sp_button(URL('delete_plugin',args=request.args), T("delete plugin"))}}
{{=sp_button(URL('design',args=request.args, anchor=request.vars.id), T("back"))}}
{{=sp_button(URL('delete_plugin',args=request.args, vars=request.vars), T("delete plugin"))}}
{{=sp_button(URL('pack_plugin',args=request.args), T("pack plugin"))}}
</span>
</div>
+3 -6
View File
@@ -40,18 +40,15 @@ import imp
import logging
logger = logging.getLogger("web2py")
import rewrite
import platform
try:
import py_compile
except:
logger.warning('unable to import py_compile')
is_pypy = hasattr(platform,'python_implementation') and \
platform.python_implementation() == 'PyPy'
settings.global_settings.is_pypy = is_pypy
is_gae = settings.global_settings.web2py_runtime_gae
is_jython = settings.global_settings.is_jython = 'java' in sys.platform.lower() or hasattr(sys, 'JYTHON_JAR') or str(sys.copyright).find('Jython') > 0
is_pypy = settings.global_settings.is_pypy
is_gae = settings.global_settings.web2py_runtime_gae
is_jython = settings.global_settings.is_jython
TEST_CODE = \
r"""
+2 -2
View File
@@ -17,7 +17,7 @@ print markmin2html(m)
from markmin2latex import markmin2latex
print markmin2latex(m)
from markmin2pdf import markmin2pdf # requires pdflatex
print markmin2pdf(m)</code></pre> ====================<h1>This is a test block with new features:</h1><p>This is a blockquote with a list with tables in it:</p><blockquote class="blockquoteclass" id="blockquoteid">This is a paragraph before list. You can continue paragraph on the next lines.<br />This is an ordered list with tables:<ol><li>Item 1</li><li>Item 2</li><li><table class="tableclass1" id="tableid1"><tbody><tr><td>aa</td><td>bb</td><td>cc</td></tr><tr><td class="num">11</td><td class="num">22</td><td class="num">33</td></tr></tbody></table></li><li>Item 4 <table class="tableclass1"><thead><tr><td>T1</td><td>T2</td><td>t3</td></tr></thead><tbody><tr><td>aaa</td><td>bbb</td><td>ccc</td></tr><tr><td>ddd</td><td>fff</td><td>ggg</td></tr><tr><td class="num">123</td><td class="num">0</td><td class="num">5.0</td></tr></tbody></table></li></ol></blockquote><p>This this a new paragraph with a table. Table has header and footer:</p><table class="tableclass1" id="tableid2"><thead><tr><td><strong>Title 1</strong></td><td><strong>Title 2</strong></td><td><strong>Title 3</strong></td></tr></thead><tbody><tr><td>data 1</td><td>data 2</td><td class="num">2.00</td></tr><tr><td>data 4</td><td>data5(long)</td><td class="num">23.00</td></tr><tr><td></td><td>data 8</td><td class="num">33.50</td></tr></tbody><tfoot><tr><td>Total:</td><td>3 items</td><td class="num">58.50</td></tr></tfoot></table><h2>Multilevel lists</h2><p>Now lists can be multilevel:</p><ol><li>Ordered item 1 on level 1. You can continue item text on next strings<ol><li><p>Ordered item 1 of sublevel 2 with a paragraph (paragraph can start with point after plus or minus characters, e.g. <strong>++.</strong> or <strong>--.</strong>)</p><li><p>This is another item. But with 3 paragraphs, blockquote and sublists:</p><p>This is the second paragraph in the item. You can add paragraphs to an item, using point notation, where first characters in the string are sequence of points with space between them and another string. For example, this paragraph (in sublevel 2) starts with two points:</p><code>.. This is the second paragraph...</code><blockquote><h3>this is a blockquote in a list</h3>You can use blockquote with headers, paragraphs, tables and lists in it:<br />Tables can have or have not header and footer. This table is defined without any header and footer in it:<table><tbody><tr><td>red</td><td>fox</td><td class="num">0</td></tr><tr><td>blue</td><td>dolphin</td><td class="num">1000</td></tr><tr><td>green</td><td>leaf</td><td class="num">10000</td></tr></tbody></table></blockquote><p>This is yet another paragraph in the item.</p><ul><li>This is an item of unordered list <strong>(sublevel 3)</strong></li><li>This is the second item of the unordered list <em>(sublevel 3)</em><ol><ol><ol><li>This is a single item of ordered list in sublevel 6</li></ol></ol><p>and this is a paragraph in sublevel 4</p></ol></li><li><p>This is a new item with paragraph in sublevel 3.</p><ol><li>Start ordered list in sublevel 4 with code block: <pre><code>line 1
print markmin2pdf(m)</code></pre> ====================<h1>This is a test block with new features:</h1><p>This is a blockquote with a list with tables in it:</p><blockquote class="blockquoteclass" id="markmin_blockquoteid">This is a paragraph before list. You can continue paragraph on the next lines.<br />This is an ordered list with tables:<ol><li>Item 1</li><li>Item 2</li><li><table class="tableclass1" id="markmin_tableid1"><tbody><tr><td>aa</td><td>bb</td><td>cc</td></tr><tr><td class="num">11</td><td class="num">22</td><td class="num">33</td></tr></tbody></table></li><li>Item 4 <table class="tableclass1"><thead><tr><td>T1</td><td>T2</td><td>t3</td></tr></thead><tbody><tr><td>aaa</td><td>bbb</td><td>ccc</td></tr><tr><td>ddd</td><td>fff</td><td>ggg</td></tr><tr><td class="num">123</td><td class="num">0</td><td class="num">5.0</td></tr></tbody></table></li></ol></blockquote><p>This this a new paragraph with a table. Table has header and footer:</p><table class="tableclass1" id="markmin_tableid2"><thead><tr><td><strong>Title 1</strong></td><td><strong>Title 2</strong></td><td><strong>Title 3</strong></td></tr></thead><tbody><tr><td>data 1</td><td>data 2</td><td class="num">2.00</td></tr><tr><td>data 4</td><td>data5(long)</td><td class="num">23.00</td></tr><tr><td></td><td>data 8</td><td class="num">33.50</td></tr></tbody><tfoot><tr><td>Total:</td><td>3 items</td><td class="num">58.50</td></tr></tfoot></table><h2>Multilevel lists</h2><p>Now lists can be multilevel:</p><ol><li>Ordered item 1 on level 1. You can continue item text on next strings<ol><li><p>Ordered item 1 of sublevel 2 with a paragraph (paragraph can start with point after plus or minus characters, e.g. <strong>++.</strong> or <strong>--.</strong>)</p><li><p>This is another item. But with 3 paragraphs, blockquote and sublists:</p><p>This is the second paragraph in the item. You can add paragraphs to an item, using point notation, where first characters in the string are sequence of points with space between them and another string. For example, this paragraph (in sublevel 2) starts with two points:</p><code>.. This is the second paragraph...</code><blockquote><h3>this is a blockquote in a list</h3>You can use blockquote with headers, paragraphs, tables and lists in it:<br />Tables can have or have not header and footer. This table is defined without any header and footer in it:<table><tbody><tr><td>red</td><td>fox</td><td class="num">0</td></tr><tr><td>blue</td><td>dolphin</td><td class="num">1000</td></tr><tr><td>green</td><td>leaf</td><td class="num">10000</td></tr></tbody></table></blockquote><p>This is yet another paragraph in the item.</p><ul><li>This is an item of unordered list <strong>(sublevel 3)</strong></li><li>This is the second item of the unordered list <em>(sublevel 3)</em><ol><ol><ol><li>This is a single item of ordered list in sublevel 6</li></ol></ol><p>and this is a paragraph in sublevel 4</p></ol></li><li><p>This is a new item with paragraph in sublevel 3.</p><ol><li>Start ordered list in sublevel 4 with code block: <pre><code>line 1
line 2
line 3</code></pre></li><li><p>Yet another item with code block:</p><pre><code> line 1
line 2
@@ -47,7 +47,7 @@ code block
X | 0 | 0
=================
**D**|**F**|**G**
-----------------:abc[id]</code></pre> is a table and is rendered as<table class="abc" id="id"><thead><tr><td><strong>A</strong></td><td><strong>B</strong></td><td><strong>C</strong></td></tr></thead><tbody><tr><td class="num">0</td><td class="num">0</td><td>X</td></tr><tr><td class="num">0</td><td>X</td><td class="num">0</td></tr><tr><td>X</td><td class="num">0</td><td class="num">0</td></tr></tbody><tfoot><tr><td><strong>D</strong></td><td><strong>F</strong></td><td><strong>G</strong></td></tr></tfoot></table> Four or more dashes delimit the table and | separates the columns. The <code>:abc</code>, <code>:id[abc_1]</code> or <code>:abc[abc_1]</code> at the end sets the class and/or id for the table and it is optional.<h3>Blockquote</h3><p>A table with a single cell is rendered as a blockquote:</p><blockquote>Hello world</blockquote><p>Blockquote can contain headers, paragraphs, lists and tables:</p><pre><code>-----
-----------------:abc[id]</code></pre> is a table and is rendered as<table class="abc" id="markmin_id"><thead><tr><td><strong>A</strong></td><td><strong>B</strong></td><td><strong>C</strong></td></tr></thead><tbody><tr><td class="num">0</td><td class="num">0</td><td>X</td></tr><tr><td class="num">0</td><td>X</td><td class="num">0</td></tr><tr><td>X</td><td class="num">0</td><td class="num">0</td></tr></tbody><tfoot><tr><td><strong>D</strong></td><td><strong>F</strong></td><td><strong>G</strong></td></tr></tfoot></table> Four or more dashes delimit the table and | separates the columns. The <code>:abc</code>, <code>:id[abc_1]</code> or <code>:abc[abc_1]</code> at the end sets the class and/or id for the table and it is optional.<h3>Blockquote</h3><p>A table with a single cell is rendered as a blockquote:</p><blockquote>Hello world</blockquote><p>Blockquote can contain headers, paragraphs, lists and tables:</p><pre><code>-----
This is a paragraph in a blockquote
+ item 1
+18 -18
View File
@@ -507,14 +507,14 @@ regex_URL=re.compile(r'@\{(?P<f>\w+)/(?P<args>.+?)\}')
regex_env=re.compile(r'@\{(?P<a>\w+?)\}')
regex_expand_meta = re.compile('('+META+'|'+DISABLED_META+')')
regex_dd=re.compile(r'\$\$(?P<latex>.*?)\$\$')
regex_code = re.compile('('+META+'|'+DISABLED_META+r')|(``(?P<t>.+?)``(?::(?P<c>\w+)(?:\[(?P<p>\S+?)\])?)?)',re.S)
regex_code = re.compile('('+META+'|'+DISABLED_META+r')|(``(?P<t>.+?)``(?::(?P<c>[a-zA-Z][_a-zA-Z\-\d]*)(?:\[(?P<p>[^\]]*)\])?)?)',re.S)
regex_strong=re.compile(r'\*\*(?P<t>[^\s*]+( +[^\s*]+)*)\*\*')
regex_del=re.compile(r'~~(?P<t>[^\s*]+( +[^\s*]+)*)~~')
regex_em=re.compile(r"''(?P<t>[^\s']+(?: +[^\s']+)*)''")
regex_num=re.compile(r"^\s*[+-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?[0-9]+)?\s*$")
regex_list=re.compile('^(?:(#{1,6}|\.+|\++|\-+)(\.)?\s+)?(.*)$')
regex_bq_headline=re.compile('^(?:(\.+|\++|\-+)(\.)?\s+)?(-{3}-*)$')
regex_tq=re.compile('^(-{3}-*)(?::(?P<c>\S+?)(?:\[(?P<p>\S+)\])?)?$')
regex_tq=re.compile('^(-{3}-*)(?::(?P<c>[a-zA-Z][_a-zA-Z\-\d]*)(?:\[(?P<p>[a-zA-Z][_a-zA-Z\-\d]*)\])?)?$')
regex_qr = re.compile(r'(?<!["\w>/=])qr:(?P<k>\w+://[\w\d\-+?&%/:.]+)',re.M)
regex_embed = re.compile(r'(?<!["\w>/=])embed:(?P<k>\w+://[\w\d\-+_=?%&/:.]+)', re.M)
regex_iframe = re.compile(r'(?<!["\w>/=])iframe:(?P<k>\w+://[\w\d\-+=?%&/:.]+)', re.M)
@@ -536,7 +536,7 @@ def markmin_escape(text):
""" insert \\ before markmin control characters: '`:*~[]{}@$ """
return regex_markmin_escape.sub(lambda m: '\\'+m.group(0).replace('\\','\\\\'), text)
def render(text,extra={},allowed={},sep='p',URL=None,environment=None,latex='google',auto=True):
def render(text,extra={},allowed={},sep='p',URL=None,environment=None,latex='google',auto=True,class_prefix='',id_prefix='markmin_'):
"""
Arguments:
- text is the text to be processed
@@ -564,13 +564,13 @@ def render(text,extra={},allowed={},sep='p',URL=None,environment=None,latex='goo
>>> render('``\\nhello\\nworld\\n``:python')
'<pre><code class="python">hello\\nworld</code></pre>'
>>> render('``hello world``:python[test_id]')
'<code class="python" id="test_id">hello world</code>'
'<code class="python" id="markmin_test_id">hello world</code>'
>>> render('``hello world``:id[test_id]')
'<code id="test_id">hello world</code>'
'<code id="markmin_test_id">hello world</code>'
>>> render('``\\nhello\\nworld\\n``:python[test_id]')
'<pre><code class="python" id="test_id">hello\\nworld</code></pre>'
'<pre><code class="python" id="markmin_test_id">hello\\nworld</code></pre>'
>>> render('``\\nhello\\nworld\\n``:id[test_id]')
'<pre><code id="test_id">hello\\nworld</code></pre>'
'<pre><code id="markmin_test_id">hello\\nworld</code></pre>'
>>> render("''hello world''")
'<p><em>hello world</em></p>'
>>> render('** hello** **world**')
@@ -699,7 +699,7 @@ def render(text,extra={},allowed={},sep='p',URL=None,environment=None,latex='goo
>>> render("the [[link \\[**without** ``<b>title</b>``:red\\] http://www.example.com]]")
'<p>the <a href="http://www.example.com">link [<strong>without</strong> <span style="color: red">&lt;b&gt;title&lt;/b&gt;</span>]</a></p>'
>>> render("aaa-META-``code``:text-LINK-[[link http://www.example.com]]-LINK-[[image http://www.picture.com img]]-end")
>>> render("aaa-META-``code``:text[]-LINK-[[link http://www.example.com]]-LINK-[[image http://www.picture.com img]]-end")
'<p>aaa-META-<code class="text">code</code>-LINK-<a href="http://www.example.com">link</a>-LINK-<img src="http://www.picture.com" alt="image" />-end</p>'
>>> render("[[<a>test</a> [<a>test2</a>] <a>text3</a>]]")
@@ -930,8 +930,8 @@ def render(text,extra={},allowed={},sep='p',URL=None,environment=None,latex='goo
) for f in s.split('|')])+'</tr>')
lineno+=1
t_cls = ' class="%s"'%t_cls if t_cls and t_cls != 'id' else ''
t_id = ' id="%s"'%t_id if t_id else ''
t_cls = ' class="%s%s"'%(class_prefix, t_cls) if t_cls and t_cls != 'id' else ''
t_id = ' id="%s%s"'%(id_prefix, t_id) if t_id else ''
s = ''
if thead:
s += '<thead>'+''.join([l for l in thead])+'</thead>'
@@ -974,8 +974,8 @@ def render(text,extra={},allowed={},sep='p',URL=None,environment=None,latex='goo
lineno+=1
t_cls = ' class="%s"'%t_cls if t_cls and t_cls != 'id' else ''
t_id = ' id="%s"'%t_id if t_id else ''
t_cls = ' class="%s%s"'%(class_prefix,t_cls) if t_cls and t_cls != 'id' else ''
t_id = ' id="%s%s"'%(id_prefix,t_id) if t_id else ''
s = '<blockquote%s%s>%s</blockquote>' \
% (t_cls,
t_id,
@@ -1166,13 +1166,13 @@ def render(text,extra={},allowed={},sep='p',URL=None,environment=None,latex='goo
bg='background-color: %s;' % c[1] if len(c)>1 and c[1] else ''
return '<span style="%s%s">%s</span>' \
% (fg, bg, render(code,{},{},'br', URL, environment, latex, auto))
cls = ' class="%s"'%b if b and b != 'id' else ''
id = ' id="%s"'%escape(p) if p else ''
if code[:1]=='\n' and code[-1:]=='\n':
cls = ' class="%s%s"'%(class_prefix,b) if b and b != 'id' else ''
id = ' id="%s%s"'%(id_prefix,escape(p)) if p else ''
beg=(code[:1]=='\n')
end=[None,-1][code[-1:]=='\n']
if beg and end:
return '<pre><code%s%s>%s</code></pre>' % (cls, id, escape(code[1:-1]))
return '<code%s%s>%s</code>' \
% (cls, id, escape(code[ (code[:1]=='\n')
: [None,-1][code[-1:]=='\n']]))
return '<code%s%s>%s</code>' % (cls, id, escape(code[beg:end]))
text = regex_expand_meta.sub(expand_meta, text)
text = text.translate(ttab_out)
return text