Skip to content

Commit

Permalink
Support media wiki table.
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen198 committed Jul 30, 2021
1 parent cb96153 commit a008f6e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
10 changes: 5 additions & 5 deletions cgi-bin/wypyplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ def rpn(v):s=[];[s.append(float(t)) if set(t).issubset(set("0123456789.-")) else
load=lambda n:(x('w/'+n) and open('w/'+n).read()) or '';load_tpl=lambda n: load(n) or load('Tpl'+n[:3]) or '';load_g=lambda:load('GlobalMenu')
f,i=cgi.FormContent(),'put type';y=f.get('p',[''])[0];y=dt.now().strftime("%b%d") if y=='Today' else (home,y)[y.isalnum()]
se='<form><input type="text"placeholder="Search.. "name="p"><input type="hidden" name="q" value="f"><button type="submit">Search</button></form>'
fs=lambda s:re.sub(pre_h,remove_leading_space,reduce(lambda s,r:re.sub('(?m)'+r[0],r[1],s),(('\r',''),('RPN\((.*?)\)', rpn),
fs=lambda s:re.sub(pre_h,remove_leading_space,reduce(lambda s,r:re.sub('(?m)'+r[0],r[1],s),(('\r',''),
('^INCLUDE\((\w+)\)$',lambda m: x('w/'+m.group(1)) and open('w/'+m.group(1)).read() or ''),
('(^|[^=/\-_A-Za-z0-9?])@(\w+)',lambda m: h+w+m.group(2)+'&amp;q=f>@'+m.group(2)+'</a>'),
('(\{\|\n)(.*[^\}]+)(\|\})',lambda m:'<table><tr><td>'+re.sub('\|{1,2}','</td><td>',re.sub('\|-','</td></tr><tr>',m.group(2)).lstrip('|'))+'</td></tr></table>'),
('RPN\((.*?)\)', rpn),('(^|[^=/\-_A-Za-z0-9?])@(\w+)',lambda m: h+w+m.group(2)+'&amp;q=f>@'+m.group(2)+'</a>'),
('(^|[^=/\-_A-Za-z0-9?])([A-Z][a-z]+([A-Z0-9][a-z0-9]*){1,})',
lambda m:(m.group(1)+'%s%s')%((m.group(2),h+w+m.group(2)+'&amp;q=e>?</a>' if edit else ''),('',h+w+m.group(2)+'>%s</a>'%m.group(2)))[x('w/'+m.group(2))]),
('^\{\{$','\n<ul>'),('^\*(.*)$','<li>\g<1></li>'),('^}}$','</ul>'),('^---$','<hr>'),
(pre,'<pre><code>\g<1></code></pre>'),('^# (.*)$',hl1),('^## (.*)$', hl2),('^### (.*)$',hl3),('\*\*(.*)\*\*','<b>\g<1></b>'),
(pre,'<pre><code>\g<1></code></pre>'),('^# (.*)$',hl1),('^## (.*)$', hl2),('^### (.*)$',hl3),('\*\*([^\*]+)\*\*','<b>\g<1></b>'),
('\!'+link,'<img src="\g<2>" alt="\g<1>">'),('(^|[^!])'+link,"\g<1>"+h+'"\g<3>">\g<2></a>'),('(^|[^"])(http[s]?:[^<>"\s]+)',
lambda m: ('<iframe width="560" height="315" src="https://www.youtube.com/embed/%s" \
frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media;\
gyroscope; picture-in-picture" allowfullscreen></iframe>' % m.group(2)[len(yt):]) if m.group(2).startswith(yt)
else (m.group(1)+h+m.group(2)+">"+m.group(2)+"</a>")),
('\n\n','\n<p>')),q(s)),0,re.MULTILINE)
else (m.group(1)+h+m.group(2)+">"+m.group(2)+"</a>")),('\n\n','\n<p>')),q(s)),0,re.MULTILINE)
do=lambda m,n:{'get':'<h1>%s%s%s>%s</a>'%(h,w,home,home) +
((':%s%s%s&amp;q=f>%s</a>%s%s%s&amp;q=e>%s</a>'%(h,w,n,n,h,w,n,edit)) if edit else '') +
'</h1>%s<p>%s'%(se if edit else '',fs(load_g()+re.sub(pre, insert_leading_space, load_tpl(n))) or n),
Expand Down
48 changes: 37 additions & 11 deletions w/DemoPage
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,50 @@ def hello():
* Item B
}}

## Table

WyPyPlus supports [media wiki style table](https://www.mediawiki.org/wiki/Help:Tables).
{|
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream
|}

{|
| Orange || Apple || more
|-
| Bread || Pie || more
|-
| Butter || Ice cream || and more
|}

## Page Break
---

## The RPN Calculator

The built-in RPN calculator supports +, -, *, /, ^ and common functions such as log, sqrt, abs, sin, cos, and tan.

3 2 ^ 4 2 ^ + sqrt = RPN(3 2 ^ 4 2 ^ + sqrt)

log10(1000)= RPN(1000 10 log)

ln(1000) = RPN( 2.718281 1000 log)

3.1415926 2 / sin = RPN( 3.1415926 2 / sin )

abs(-10) = RPN(-10 fabs)

Print the entire stack on error: RPN(2 3 abc)
{|
| ** Example** || **Results**
|-
| 3 2 ^ 4 2 ^ + sqrt || RPN(3 2 ^ 4 2 ^ + sqrt)
|-
| log10(1000) || RPN(1000 10 log)
|-
| ln(1000) || RPN( 2.718281 1000 log)
|-
| 3.1415926 2 / sin || RPN( 3.1415926 2 / sin )
|-
| abs(-10) || RPN(-10 fabs)
|-
| Print the entire stack on error || RPN(2 3 abc)
|}

You can easily add more functions to the built-in RPN by modify this line:
```
Expand Down

0 comments on commit a008f6e

Please sign in to comment.