ó
Ñs/Uc           @   s  d  d l  Z  d  d l Z d  d l m Z d  d l m Z y  d  d l m Z d  d l Z Wn0 e	 k
 rŠ d  d l
 m Z d  d l j Z n Xd d d g Z d Z d	 d
 d d d d d d d d d d d d d d g Z d Z d Z d Z d Z e  j d ƒ Z e  j d ƒ Z e  j d e d  e d! ƒ Z e  j d" ƒ Z e  j d e d  e d# e  j ƒ Z e  j d$ ƒ Z e  j d% ƒ Z e  j d& ƒ Z e  j d' ƒ Z e  j d( ƒ Z e  j d) ƒ Z e  j d* ƒ Z  e  j d+ e  j! ƒ Z" e  j d, e  j! ƒ Z# e  j d e d- e  j ƒ Z$ e  j d. e  j ƒ Z% e  j d/ e  j ƒ Z& e  j d0 ƒ Z' e  j d1 ƒ Z( e d2 d3 ƒ Z) e d3 d2 ƒ Z* e  j d4 ƒ Z+ d5 „  Z, d6 „  Z- d7 „  Z. d8 „  Z/ d9 „  Z0 d: „  Z1 d; „  Z2 d< „  Z3 d= „  Z4 i  i  d> e5 e5 d? d@ d@ dA dB e6 dC „ Z7 i  i  d> d@ d@ dA dB e6 dD „ Z8 dE „  Z9 e: dF k r‰d  d l; Z; d  d l< Z< d  dG l= m> Z> e> dH ƒ dI Z? e; j@ dI dJ !dK g k rÃe> dL ƒ dI ZA e? eB dM dN dO eA dP e8 e dQ eC ƒƒ GHnÃe; j@ dI dJ !dR g k rNd  dS lD mE ZE dT ZF eE dU dV ƒ ZG dW GHeH g  eI dX ƒ D] ZJ eG jD eF ƒ ^ qƒ ZK dY eF eK dT eF f GHn8eL e; j@ ƒ dI k rWeM e; j@ dI dZ ƒ ZN zÍ eN jO ƒ  ZP eL e; j@ ƒ dJ k re; j@ dJ jQ d[ ƒ rÏd\ e; j@ dJ dI d] ZR n< eM e; j@ dJ dZ ƒ ZS z d^ eS jO ƒ  d_ ZR Wd eS jT ƒ  Xn dA ZR e? eB dM e; j@ dI dO eR dP e8 eP dQ eC ƒƒ GHWd eN jT ƒ  Xn/ d` e; j@ da db GHdc GHdd GHde GHdf GHe9 ƒ  n  d S(g   iÿÿÿÿN(   t   escape(   t	   maketrans(   t   parset   rendert   markmin2htmlt   markmin_escapesl/  
# Markmin markup language

## About

This is a new markup language that we call markmin designed to produce high quality scientific papers and books and also put them online. We provide serializers for html, latex and pdf. It is implemented in the ``markmin2html`` function in the ``markmin2html.py``.

Example of usage:

``
m = "Hello **world** [[link http://web2py.com]]"
from markmin2html import markmin2html
print markmin2html(m)
from markmin2latex import markmin2latex
print markmin2latex(m)
from markmin2pdf import markmin2pdf # requires pdflatex
print markmin2pdf(m)
``
====================
# This is a test block
  with new features:
This is a blockquote with
a list with tables in it:
-----------
  This is a paragraph before list.
  You can continue paragraph on the
  next lines.

  This is an ordered list with tables:
  + Item 1
  + Item 2
  + --------
    aa|bb|cc
    11|22|33
    --------:tableclass1[tableid1]
  + Item 4
    -----------
     T1| T2| t3
    ===========
    aaa|bbb|ccc
    ddd|fff|ggg
    123|0  |5.0
    -----------:tableclass1
-----------:blockquoteclass[blockquoteid]

This this a new paragraph
with a followed table.
Table has header, footer, sections,
odd and even rows:
-------------------------------
**Title 1**|**Title 2**|**Title 3**
==============================
data 1     | data 2    |  2.00
data 3     |data4(long)| 23.00
           |data 5     | 33.50
==============================
New section|New data   |  5.00
data 1     |data2(long)|100.45
           |data 3     | 12.50
data 4     | data 5    |   .33
data 6     |data7(long)|  8.01
           |data 8     |   514
==============================
Total:     | 9 items   |698,79
------------------------------:tableclass1[tableid2]

## Multilevel
   lists

Now lists can be multilevel:

+ Ordered item 1 on level 1.
  You can continue item text on
  next strings

. paragraph in an item

++. Ordered item 1 of sublevel 2 with
    a paragraph (paragraph can start
    with point after plus or minus
    characters, e.g. **++.** or **--.**)

++. This is another item. But with 3 paragraphs,
    blockquote and sublists:

.. 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:
   ``.. This is the second paragraph...``

.. ----------
     ### this is a blockquote in a list

     You can use blockquote with headers, paragraphs,
     tables and lists in it:

     Tables can have or have not header and footer.
     This table is defined without any header
     and footer in it:
     ---------------------
     red  |fox     | 0
     blue |dolphin | 1000
     green|leaf    | 10000
     ---------------------
   ----------

.. This is yet another paragraph in the item.

--- This is an item of unordered list **(sublevel 3)**
--- This is the second item of the unordered list ''(sublevel 3)''

++++++ This is a single item of ordered list in sublevel 6
.... and this is a paragraph in sublevel 4
---. This is a new item with paragraph in sublevel 3.
++++ Start ordered list in sublevel 4 with code block: ``
line 1
  line 2
     line 3
``
++++. Yet another item with code block (we need to indent \`\` to add code block as part of item):
 ``
  line 1
line 2
  line 3
``
 This item finishes with this paragraph.

... Item in sublevel 3 can be continued with paragraphs.

... ``
  this is another
code block
    in the
  sublevel 3 item
``

+++ The last item in sublevel 3
.. This is a continuous paragraph for item 2 in sublevel 2.
   You can use such structure to create difficult structured
   documents.

++ item 3 in sublevel 2
-- item 1 in sublevel 2 (new unordered list)
-- item 2 in sublevel 2
-- item 3 in sublevel 2

++ item 1 in sublevel 2 (new ordered list)
++ item 2 in sublevel 2
++ item 3 in sublevle 2

+ item 2 in level 1
+ item 3 in level 1
- new unordered list (item 1 in level 1)
- level 2 in level 1

- level 3 in level 1
- level 4 in level 1
## This is the last section of the test

Single paragraph with '----' in it will be turned into separator:

-----------

And this is the last paragraph in
the test. Be happy!

====================

## Why?

We wanted a markup language with the following requirements:
- less than 300 lines of functional code
- easy to read
- secure
- support table, ul, ol, code
- support html5 video and audio elements (html serialization only)
- can align images and resize them
- can specify class for tables, blockquotes and code elements
- can add anchors
- does not use _ for markup (since it creates odd behavior)
- automatically links urls
- fast
- easy to extend
- supports latex and pdf including references
- allows to describe the markup in the markup (this document is generated from markmin syntax)

(results depend on text but in average for text ~100K markmin is 30% faster than markdown, for text ~10K it is 10x faster)

The [[web2py book http://www.lulu.com/product/paperback/web2py-%283rd-edition%29/12822827]] published by lulu, for example, was entirely generated with markmin2pdf from the online [[web2py wiki http://www.web2py.com/book]]

## Download

- http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2html.py
- http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2latex.py
- http://web2py.googlecode.com/hg/gluon/contrib/markmin/markmin2pdf.py

markmin2html.py and markmin2latex.py are single files and have no web2py dependence. Their license is BSD.

## Examples

### Bold, italic, code and links

------------------------------------------------------------------------------
**SOURCE**                                    | **OUTPUT**
==============================================================================
``# title``                                   | **title**
``## section``                                | **section**
``### subsection``                            | **subsection**
``**bold**``                                  | **bold**
``''italic''``                                | ''italic''
``~~strikeout~~``                             | ~~strikeout~~
``!`!`verbatim`!`!``                          | ``verbatim``
``\`\`color with **bold**\`\`:red``           | ``color with **bold**``:red
``\`\`many colors\`\`:color[blue:#ffff00]``   | ``many colors``:color[blue:#ffff00]
``http://google.com``                         | http://google.com
``[[**click** me #myanchor]]``                | [[**click** me #myanchor]]
``[[click me [extra info] #myanchor popup]]`` | [[click me [extra info] #myanchor popup]]
-------------------------------------------------------------------------------

### More on links

The format is always ``[[title link]]`` or ``[[title [extra] link]]``. Notice you can nest bold, italic, strikeout and code inside the link ``title``.

### Anchors [[myanchor]]

You can place an anchor anywhere in the text using the syntax ``[[name]]`` where ''name'' is the name of the anchor.
You can then link the anchor with [[link #myanchor]], i.e. ``[[link #myanchor]]`` or [[link with an extra info [extra info] #myanchor]], i.e.
``[[link with an extra info [extra info] #myanchor]]``.

### Images

[[alt-string for the image [the image title] http://www.web2py.com/examples/static/web2py_logo.png right 200px]]
This paragraph has an image aligned to the right with a width of 200px. Its is placed using the code

``[[alt-string for the image [the image title] http://www.web2py.com/examples/static/web2py_logo.png right 200px]]``.

### Unordered Lists

``
- Dog
- Cat
- Mouse
``

is rendered as
- Dog
- Cat
- Mouse

Two new lines between items break the list in two lists.

### Ordered Lists

``
+ Dog
+ Cat
+ Mouse
``

is rendered as
+ Dog
+ Cat
+ Mouse


### Multilevel Lists

``
+ Dogs
 -- red
 -- brown
 -- black
+ Cats
 -- fluffy
 -- smooth
 -- bald
+ Mice
 -- small
 -- big
 -- huge
``

is rendered as
+ Dogs
 -- red
 -- brown
 -- black
+ Cats
 -- fluffy
 -- smooth
 -- bald
+ Mice
 -- small
 -- big
 -- huge


### Tables (with optional header and/or footer)

Something like this
``
-----------------
**A**|**B**|**C**
=================
  0  |  0  |  X
  0  |  X  |  0
  X  |  0  |  0
=================
**D**|**F**|**G**
-----------------:abc[id]
``
is a table and is rendered as
-----------------
**A**|**B**|**C**
=================
0 | 0 | X
0 | X | 0
X | 0 | 0
=================
**D**|**F**|**G**
-----------------:abc[id]
Four or more dashes delimit the table and | separates the columns.
The ``:abc``, ``:id[abc_1]`` or ``:abc[abc_1]`` at the end sets the class and/or id for the table and it is optional.

### Blockquote

A table with a single cell is rendered as a blockquote:

-----
Hello world
-----

Blockquote can contain headers, paragraphs, lists and tables:

``
-----
  This is a paragraph in a blockquote

  + item 1
  + item 2
  -- item 2.1
  -- item 2.2
  + item 3

  ---------
  0 | 0 | X
  0 | X | 0
  X | 0 | 0
  ---------:tableclass1
-----
``

is rendered as:
-----
  This is a paragraph in a blockquote

  + item 1
  + item 2
  -- item 2.1
  -- item 2.2
  + item 3

  ---------
  0 | 0 | X
  0 | X | 0
  X | 0 | 0
  ---------:tableclass1
-----


### Code, ``<code>``, escaping and extra stuff

``
def test():
    return "this is Python code"
``:python

Optionally a ` inside a ``!`!`...`!`!`` block can be inserted escaped with !`!.

**NOTE:** You can escape markmin constructions (\'\',\`\`,\*\*,\~\~,\[,\{,\]\},\$,\@) with '\\' character:
 so \\`\\` can replace !`!`! escape string

The ``:python`` after the markup is also optional. If present, by default, it is used to set the class of the <code> block.
The behavior can be overridden by passing an argument ``extra`` to the ``render`` function. For example:

``
markmin2html("!`!!`!aaa!`!!`!:custom",
             extra=dict(custom=lambda text: 'x'+text+'x'))
``:python

generates

``'xaaax'``:python

(the ``!`!`...`!`!:custom`` block is rendered by the ``custom=lambda`` function passed to ``render``).

### Line breaks

``[[NEWLINE]]`` tag is used to break lines:
``
#### Multiline [[NEWLINE]]
   title
paragraph [[NEWLINE]]
with breaks[[NEWLINE]]in it
``
generates:

#### Multiline [[NEWLINE]]
   title
paragraph [[NEWLINE]]
with breaks[[NEWLINE]]in it


### Html5 support

Markmin also supports the <video> and <audio> html5 tags using the notation:
``
[[message link video]]
[[message link audio]]

[[message [title] link video]]
[[message [title] link audio]]
``
where ``message`` will be shown in browsers without HTML5 video/audio tags support.

### Latex and other extensions

Formulas can be embedded into HTML with ''\$\$``formula``\$\$''.
You can use Google charts to render the formula:

``
LATEX = '<img src="http://chart.apis.google.com/chart?cht=tx&chl=%s" />'
markmin2html(text,{'latex':lambda code: LATEX % urllib.quote(code)})
``

### Code with syntax highlighting

This requires a syntax highlighting tool, such as the web2py CODE helper.

``
extra={'code_cpp':lambda text: CODE(text,language='cpp').xml(),
       'code_java':lambda text: CODE(text,language='java').xml(),
       'code_python':lambda text: CODE(text,language='python').xml(),
       'code_html':lambda text: CODE(text,language='html').xml()}
``
or simple:
``
extra={'code':lambda text,lang='python': CODE(text,language=lang).xml()}
``
``
markmin2html(text,extra=extra)
``

Code can now be marked up as in this example:
``
!`!`
<html><body>example</body></html>
!`!`:code_html
``
OR
``
!`!`
<html><body>example</body></html>
!`!`:code[html]
``

### Citations and References

Citations are treated as internal links in html and proper citations in latex if there is a final section called "References". Items like

``
- [[key]] value
``

in the References will be translated into Latex

``
\bibitem{key} value
``

Here is an example of usage:

``
As shown in Ref.!`!`mdipierro`!`!:cite

## References

- [[mdipierro]] web2py Manual, 3rd Edition, lulu.com
``

### Caveats

``<ul/>``, ``<ol/>``, ``<code/>``, ``<table/>``, ``<blockquote/>``, ``<h1/>``, ..., ``<h6/>`` do not have ``<p>...</p>`` around them.

t   aquat   blackt   bluet   fuchsiat   grayt   greent   limet   maroont   navyt   olivet   purplet   redt   silvert   tealt   whitet   yellows   s   s   s>   <img src="http://chart.apis.google.com/chart?cht=tx&chl=%s" />sB   @/(?P<a>\w*)/(?P<c>\w*)/(?P<f>\w*(\.\w+)?)(/(?P<args>[\w\.\-/]+))?s%   @\{(?P<a>[\w\-\.]+?)(\:(?P<b>.*?))?\}t   (t   |s   |````)s   \$\$(?P<latex>.*?)\$\$sP   |````)|(``(?P<t>.+?)``(?::(?P<c>[a-zA-Z][_a-zA-Z\-\d]*)(?:\[(?P<p>[^\]]*)\])?)?)s"   \*\*(?P<t>[^\s*]+( +[^\s*]+)*)\*\*s   ~~(?P<t>[^\s*]+( +[^\s*]+)*)~~s   ''(?P<t>([^\s']| |'(?!'))+)''s4   ^\s*[+-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?[0-9]+)?\s*$s1   ^(?:(?:(#{1,6})|(?:(\.+|\++|\-+)(\.)?))\s*)?(.*)$s$   ^(?:(\.+|\++|\-+)(\.)?\s+)?(-{3}-*)$sS   ^(-{3}-*)(?::(?P<c>[a-zA-Z][_a-zA-Z\-\d]*)(?:\[(?P<p>[a-zA-Z][_a-zA-Z\-\d]*)\])?)?$s6   (?<!["\w>/=])(?P<p>\w+):(?P<k>\w+://[\w\d\-+=?%&/:.]+)sC   (?<!["\w>/=])(?P<k>\w+://[\w\d\-+_=?%&/:.,;#]+\w|[\w\-.]+@[\w\-.]+)s   )|\[\[(?P<s>.+?)\]\]sN   ^(?P<t>\S.*?)?(?:\s+\[(?P<a>.+?)\])?(?:\s+(?P<k>\S+))?(?:\s+(?P<p>popup))?\s*$s’   ^(?P<t>\S.*?)?(?:\s+\[(?P<a>.+?)\])?(?:\s+(?P<k>\S+))?\s+(?P<p>img|IMG|left|right|center|video|audio|blockleft|blockright)(?:\s+(?P<w>\d+px))?\s*$s   (\\*)(['`:*~\\[\]{}@\$+\-.#\n])s   \\(['`:*~\\[\]{}@\$+\-.#\n])s   '`:*~\[]{}@$+-.#
s   s   (?P<name>\w+?)\s*\=\s*c         C   s   d t  j d |  ƒ S(   Ns   {%s}s   '\g<name>':(   t   regex_quotet   sub(   t   b(    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt	   make_dict5  s    c            s†   i d d 6t d 6t d 6‰ ˆ j | ƒ t |  t ƒ rL t |  d d ƒ}  n  t |  t j ƒ rj |  j	 }  n  ‡  ‡ f d †  ‰  ˆ  |  ƒ S(   sú   
    Safely evaluate an expression node or a string containing a Python
    expression.  The string or node provided may only consist of the following
    Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
    and None.
    t   Nonet   Truet   Falset   modet   evalc      
      sº  t  |  t j ƒ r |  j St  |  t j ƒ r2 |  j St  |  t j ƒ rZ t t ˆ  |  j	 ƒ ƒ St  |  t j
 ƒ r‚ t t ˆ  |  j	 ƒ ƒ St  |  t j ƒ r½ t ‡  f d †  t |  j |  j ƒ Dƒ ƒ St  |  t j ƒ rì |  j ˆ k rªˆ |  j Sn¾ t  |  t j ƒ rªt  |  j t t f ƒ rªt  |  j t ƒ rªt  |  j j t ƒ rªt  |  j t ƒ rªt  |  j j t t t f ƒ rª|  j j } |  j j } t  |  j t ƒ rŸ| | S| | Sn  t d ƒ ‚ d  S(   Nc         3   s-   |  ]# \ } } ˆ  | ƒ ˆ  | ƒ f Vq d  S(   N(    (   t   .0t   kt   v(   t   _convert(    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pys	   <genexpr>O  s    s   malformed string(   t
   isinstancet   astt   Strt   st   Numt   nt   Tuplet   tuplet   mapt   eltst   Listt   listt   Dictt   dictt   zipt   keyst   valuest   Namet   idt   BinOpt   opt   Addt   Subt   rightt   complext   leftt   intt   longt   floatt
   ValueError(   t   nodeR>   R<   (   R$   t   _safe_names(    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyR$   E  s4    N(
   R   R   R   t   updateR%   t
   basestringt	   ast_parseR&   t
   Expressiont   body(   t   node_or_stringt   env(    (   R$   RD   sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt	   safe_eval8  s    c         C   s   t  j d „  |  ƒ S(   s9    insert \ before markmin control characters: '`:*~[]{}@$ c         S   s   d |  j  d ƒ j d d ƒ S(   Ns   \i    s   \\(   t   groupt   replace(   t   m(    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   <lambda>f  s    (   t   regex_markmin_escapeR   (   t   text(    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyR   c  s    c            s   t  j ‡  f d †  |  ƒ S(   Nc            s   ˆ  |  j  d ƒ ƒ S(   NR"   (   RM   (   RO   (   t	   autolinks(    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyRP   i  s    (   t
   regex_autoR   (   RR   RS   (    (   RS   sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   replace_autolinksh  s    c         C   s   | d „ } t  j | |  ƒ S(   Nc         S   sp   |  j  d d d d ƒ \ } } } } | d | p3 d  d | p? d  d | pK d  d | pW d j d ƒ d t d t ƒ S(	   Nt   at   ct   ft   argst    t   /t   schemet   host(   RM   R   t   splitR   (   t   matcht   urlRV   RW   RX   RY   (    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   u1m  s    $*(   t	   regex_URLR   (   RR   R`   Ra   (    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   replace_at_urlsk  s    c         C   s"   | d „ } t  j | |  ƒ }  |  S(   Nc         S   s»   | j  |  j d ƒ |  j d ƒ ƒ } t | ƒ r· |  j d ƒ } y t t | ƒ | ƒ } Wn n Xy+ t | t ƒ r€ | |   n	 | | ƒ } Wn t k
 r¬ } d | } n Xt | ƒ Sd  S(   NRV   i    R   s	   ERROR: %s(	   t   getRM   t   callableRL   R   R%   R2   t	   Exceptiont   str(   R_   RK   RX   R   t   e(    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   u2u  s    $+(   t
   regex_env2R   (   RR   RK   Ri   (    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   replace_componentss  s    c         C   s…   |  j  ƒ  } d |  k r2 d |  k r2 d |  |  f S| j d ƒ rI d |  S| j d ƒ r` d |  S| j d ƒ rw d |  Sd |  |  f S(   sR   
    it automatically converts the url to link,
    image, video or audio tag
    t   @s   ://s   <a href="mailto:%s">%s</a>s   .jpgs   .jpegs   .gifs   .pngs   <img src="%s" controls />s   .mp4s   .mpegs   .movs   .ogvs!   <video src="%s" controls></video>s   .mp3s   .wavs   .oggs!   <audio src="%s" controls></audio>s   <a href="%s">%s</a>(   s   .jpgs   .jpegs   .gifs   .png(   s   .mp4s   .mpegs   .movs   .ogv(   s   .mp3s   .wavs   .ogg(   t   lowert   endswith(   R`   t   u_url(    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   autolinks_simple…  s    c         C   s4   |  d k r d | S|  d k r( d | S|  d | S(   s  
    it converts url to html-string using appropriate proto-prefix:
    Uses for construction "proto:url", e.g.:
        "iframe:http://www.example.com/path" will call protolinks()
        with parameters:
            proto="iframe"
            url="http://www.example.com/path"
    t   iframet   embeds:   <iframe src="%s" frameborder="0" allowfullscreen></iframe>t   qrsŽ   <img style="width:100px" src="http://chart.apis.google.com/chart?cht=qr&chs=100x100&chl=%s&choe=UTF-8&chld=H" alt="QR Code" title="QR Code" />t   :(   s   iframeRr   (    (   t   protoR`   (    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   protolinks_simple•  s
    	c         C   s   d |  |  f S(   Ns   <a href="mailto:%s">%s</a>(    (   t   email(    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   email_simple¦  s    t   pt   googlet   defaultRZ   t   markmin_c             sa  ˆ d k r t  ‰ n  ˆ d k r* t ‰ n  ˆ r6 d n d ‰ t |  t ƒ r] |  j d ƒ }  n  t |  pi d ƒ }  t j d „  |  ƒ }  |  j d d ƒ j d d ƒ }  ˆ  d! k	 rÀ t
 |  ˆ  ƒ }  n  ˆ	 d k rá t j d	 |  ƒ }  n  g  ‰ ‡ ‡ f d
 †  } t j | |  ƒ }  g  ‰
 ‡
 f d †  } t j | |  ƒ }  t |  ƒ }  ˆ rbt j ‡ f d †  |  ƒ }  n  ˆ rzt |  ˆ ƒ }  n  |  j d ƒ ‰ ‡ ‡ ‡ ‡ ‡ f d †  } ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ f d †  ‰ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ f	 d †  ‰ ‡ ‡ ‡ ‡ ‡ f d †  ‰ | d k r/d ‰ d ˆ ‰ d ‰ n& d ‰ ‰ | d k rOd ˆ n d ‰ d } d } g  ‰ g  ‰ g  ‰ g  ‰ d } d } t ˆ ƒ ‰ x| ˆ k  r¢ˆ | d  } ˆ | j ƒ  } | } | d  } | r•| d k r/t j | ƒ d \ } } } } | s| r/| d k r<| | | ƒ \ } } | d 7} q”q,| d k rˆ | | | d | | | ƒ \ } } } | d 7} q”q,| d k rì| s—| rÎˆ | | | d | | | ƒ \ } } } | d 7} q”q)ˆ | | | ƒ \ } } } q,| d k r,ˆ | | | | | ƒ \ } } } | d 7} q”q,q/n  | d k r\| d k sS| t k r\d } n  | d k s€| d k r*| d+ k r*ˆ j ˆ d! d! d" … ƒ g  ‰ g  ‰ g  ‰ d } ˆ rÔ| d k rÔˆ j ˆ ƒ n  | d k r| t k rˆ rþˆ g ‰ n  ˆ j ˆ ƒ d } n d } ˆ j | ƒ q•| d k r| d# k r| t k rˆ j ˆ j ƒ  ƒ ˆ j ƒ  ˆ j | ƒ d } q•ˆ j d | ƒ n  | d 7} q”Wˆ j ˆ d! d! d" … ƒ d j ˆ ƒ }  t j d$ |  ƒ }  t j d% |  ƒ }  t j d& |  ƒ }  ‡  ‡ ‡ ‡ ‡ ‡	 ‡ ‡ ‡ f	 d' †  } ‡  ‡ ‡ ‡ ‡ ‡	 ‡ ‡ ‡ f	 d( †  } |  j t ƒ } | d }  x‘ t ˆ
 ƒ D]ƒ \ } } | d! k r—t } nL t  j | | ƒ } | | k rÊt! j | | ƒ } n  | | k rãd) | } n  |  | | | d 7}  qvW‡  ‡ ‡ ‡ ‡ ‡ ‡	 ‡ ‡ ‡ ‡ f d* †  } t" j | |  ƒ }  ˆ rTt# |  ˆ ƒ }  n  |  j$ t% ƒ S(,   s^0  
    Arguments:
    - text is the text to be processed
    - extra is a dict like extra=dict(custom=lambda value: value) that process custom code
      as in " ``this is custom code``:custom "
    - allowed is a dictionary of list of allowed classes like
      allowed = dict(code=('python','cpp','java'))
    - sep can be 'p' to separate text in <p>...</p>
      or can be 'br' to separate text using <br />
    - URL -
    - environment is a dictionary of environment variables (can be accessed with @{variable}
    - latex -
    - autolinks is a function to convert auto urls to html-code (default is autolinks(url) )
    - protolinks is a function to convert proto-urls (e.g."proto:url") to html-code
      (default is protolinks(proto,url))
    - class_prefix is a prefix for ALL classes in markmin text. E.g. if class_prefix='my_'
      then for ``test``:cls class will be changed to "my_cls" (default value is '')
    - id_prefix is prefix for ALL ids in markmin text (default value is 'markmin_'). E.g.:
        -- [[id]] will be converted to <span class="anchor" id="markmin_id"></span>
        -- [[link #id]] will be converted to <a href="#markmin_id">link</a>
        -- ``test``:cls[id] will be converted to <code class="cls" id="markmin_id">test</code>

    >>> render('this is\n# a section\n\nparagraph')
    '<p>this is</p><h1>a section</h1><p>paragraph</p>'
    >>> render('this is\n## a subsection\n\nparagraph')
    '<p>this is</p><h2>a subsection</h2><p>paragraph</p>'
    >>> render('this is\n### a subsubsection\n\nparagraph')
    '<p>this is</p><h3>a subsubsection</h3><p>paragraph</p>'
    >>> render('**hello world**')
    '<p><strong>hello world</strong></p>'
    >>> render('``hello world``')
    '<code>hello world</code>'
    >>> render('``hello world``:python')
    '<code class="python">hello world</code>'
    >>> render('``\nhello\nworld\n``:python')
    '<pre><code class="python">hello\nworld</code></pre>'
    >>> render('``hello world``:python[test_id]')
    '<code class="python" id="markmin_test_id">hello world</code>'
    >>> render('``hello world``:id[test_id]')
    '<code id="markmin_test_id">hello world</code>'
    >>> render('``\nhello\nworld\n``:python[test_id]')
    '<pre><code class="python" id="markmin_test_id">hello\nworld</code></pre>'
    >>> render('``\nhello\nworld\n``:id[test_id]')
    '<pre><code id="markmin_test_id">hello\nworld</code></pre>'
    >>> render("''hello world''")
    '<p><em>hello world</em></p>'
    >>> render('** hello** **world**')
    '<p>** hello** <strong>world</strong></p>'

    >>> render('- this\n- is\n- a list\n\nand this\n- is\n- another')
    '<ul><li>this</li><li>is</li><li>a list</li></ul><p>and this</p><ul><li>is</li><li>another</li></ul>'

    >>> render('+ this\n+ is\n+ a list\n\nand this\n+ is\n+ another')
    '<ol><li>this</li><li>is</li><li>a list</li></ol><p>and this</p><ol><li>is</li><li>another</li></ol>'

    >>> render("----\na | b\nc | d\n----\n")
    '<table><tbody><tr class="first"><td>a</td><td>b</td></tr><tr class="even"><td>c</td><td>d</td></tr></tbody></table>'

    >>> render("----\nhello world\n----\n")
    '<blockquote>hello world</blockquote>'

    >>> render('[[myanchor]]')
    '<p><span class="anchor" id="markmin_myanchor"></span></p>'

    >>> render('[[ http://example.com]]')
    '<p><a href="http://example.com">http://example.com</a></p>'

    >>> render('[[bookmark [http://example.com] ]]')
    '<p><span class="anchor" id="markmin_bookmark"><a href="http://example.com">http://example.com</a></span></p>'

    >>> render('[[this is a link http://example.com]]')
    '<p><a href="http://example.com">this is a link</a></p>'

    >>> render('[[this is an image http://example.com left]]')
    '<p><img src="http://example.com" alt="this is an image" style="float:left" /></p>'

    >>> render('[[this is an image http://example.com left 200px]]')
    '<p><img src="http://example.com" alt="this is an image" style="float:left;width:200px" /></p>'

    >>> render("[[Your browser doesn't support <video> HTML5 tag http://example.com video]]")
    '<p><video controls="controls"><source src="http://example.com" />Your browser doesn\'t support &lt;video&gt; HTML5 tag</video></p>'

    >>> render("[[Your browser doesn't support <audio> HTML5 tag http://example.com audio]]")
    '<p><audio controls="controls"><source src="http://example.com" />Your browser doesn\'t support &lt;audio&gt; HTML5 tag</audio></p>'

    >>> render("[[Your\nbrowser\ndoesn't\nsupport\n<audio> HTML5 tag http://exam\\\nple.com\naudio]]")
    '<p><audio controls="controls"><source src="http://example.com" />Your browser doesn\'t support &lt;audio&gt; HTML5 tag</audio></p>'

    >>> render('[[this is a **link** http://example.com]]')
    '<p><a href="http://example.com">this is a <strong>link</strong></a></p>'

    >>> render("``aaa``:custom", extra=dict(custom=lambda text: 'x'+text+'x'))
    'xaaax'

    >>> print render(r"$$\int_a^b sin(x)dx$$")
    <img src="http://chart.apis.google.com/chart?cht=tx&chl=%5Cint_a%5Eb%20sin%28x%29dx" />

    >>> markmin2html(r"use backslash: \[\[[[mess\[[ag\]]e link]]\]]")
    '<p>use backslash: [[<a href="link">mess[[ag]]e</a>]]</p>'

    >>> markmin2html("backslash instead of exclamation sign: \``probe``")
    '<p>backslash instead of exclamation sign: ``probe``</p>'

    >>> render(r"simple image: [[\[[this is an image\]] http://example.com IMG]]!!!")
    '<p>simple image: <img src="http://example.com" alt="[[this is an image]]" />!!!</p>'

    >>> render(r"simple link no anchor with popup: [[ http://example.com popup]]")
    '<p>simple link no anchor with popup: <a href="http://example.com" target="_blank">http://example.com</a></p>'

    >>> render("auto-url: http://example.com")
    '<p>auto-url: <a href="http://example.com">http://example.com</a></p>'

    >>> render("auto-image: (http://example.com/image.jpeg)")
    '<p>auto-image: (<img src="http://example.com/image.jpeg" controls />)</p>'

    >>> render("qr: (qr:http://example.com/image.jpeg)")
    '<p>qr: (<img style="width:100px" src="http://chart.apis.google.com/chart?cht=qr&chs=100x100&chl=http://example.com/image.jpeg&choe=UTF-8&chld=H" alt="QR Code" title="QR Code" />)</p>'

    >>> render("embed: (embed:http://example.com/page)")
    '<p>embed: (<iframe src="http://example.com/page" frameborder="0" allowfullscreen></iframe>)</p>'

    >>> render("iframe: (iframe:http://example.com/page)")
    '<p>iframe: (<iframe src="http://example.com/page" frameborder="0" allowfullscreen></iframe>)</p>'

    >>> render("title1: [[test message [simple \[test\] title] http://example.com ]] test")
    '<p>title1: <a href="http://example.com" title="simple [test] title">test message</a> test</p>'

    >>> render("title2: \[\[[[test message [simple title] http://example.com popup]]\]]")
    '<p>title2: [[<a href="http://example.com" title="simple title" target="_blank">test message</a>]]</p>'

    >>> render("title3: [[ [link w/o anchor but with title] http://www.example.com ]]")
    '<p>title3: <a href="http://www.example.com" title="link w/o anchor but with title">http://www.example.com</a></p>'

    >>> render("title4: [[ [simple title] http://www.example.com popup]]")
    '<p>title4: <a href="http://www.example.com" title="simple title" target="_blank">http://www.example.com</a></p>'

    >>> render("title5: [[test message [simple title] http://example.com IMG]]")
    '<p>title5: <img src="http://example.com" alt="test message" title="simple title" /></p>'

    >>> render("title6: [[[test message w/o title] http://example.com IMG]]")
    '<p>title6: <img src="http://example.com" alt="[test message w/o title]" /></p>'

    >>> render("title7: [[[this is not a title] [this is a title] http://example.com IMG]]")
    '<p>title7: <img src="http://example.com" alt="[this is not a title]" title="this is a title" /></p>'

    >>> render("title8: [[test message [title] http://example.com center]]")
    '<p>title8: <p style="text-align:center"><img src="http://example.com" alt="test message" title="title" /></p></p>'

    >>> render("title9: [[test message [title] http://example.com left]]")
    '<p>title9: <img src="http://example.com" alt="test message" title="title" style="float:left" /></p>'

    >>> render("title10: [[test message [title] http://example.com right 100px]]")
    '<p>title10: <img src="http://example.com" alt="test message" title="title" style="float:right;width:100px" /></p>'

    >>> render("title11: [[test message [title] http://example.com center 200px]]")
    '<p>title11: <p style="text-align:center"><img src="http://example.com" alt="test message" title="title" style="width:200px" /></p></p>'

    >>> render(r"\[[probe]]")
    '<p>[[probe]]</p>'

    >>> render(r"\\[[probe]]")
    '<p>\\<span class="anchor" id="markmin_probe"></span></p>'

    >>> render(r"\\\[[probe]]")
    '<p>\\[[probe]]</p>'

    >>> render(r"\\\\[[probe]]")
    '<p>\\\\<span class="anchor" id="markmin_probe"></span></p>'

    >>> render(r"\\\\\[[probe]]")
    '<p>\\\\[[probe]]</p>'

    >>> render(r"\\\\\\[[probe]]")
    '<p>\\\\\\<span class="anchor" id="markmin_probe"></span></p>'

    >>> render("``[[ [\[[probe\]\]] URL\[x\]]]``:red[dummy_params]")
    '<span style="color: red"><a href="URL[x]" title="[[probe]]">URL[x]</a></span>'

    >>> render("the \**text**")
    '<p>the **text**</p>'

    >>> render("the \``text``")
    '<p>the ``text``</p>'

    >>> render("the \\''text''")
    "<p>the ''text''</p>"

    >>> render("the [[link [**with** ``<b>title</b>``:red] http://www.example.com]]")
    '<p>the <a href="http://www.example.com" title="**with** ``&lt;b&gt;title&lt;/b&gt;``:red">link</a></p>'

    >>> 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")
    '<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>]]")
    '<p><a href="&lt;a&gt;text3&lt;/a&gt;" title="&lt;a&gt;test2&lt;/a&gt;">&lt;a&gt;test&lt;/a&gt;</a></p>'

    >>> render("[[<a>test</a> [<a>test2</a>] <a>text3</a> IMG]]")
    '<p><img src="&lt;a&gt;text3&lt;/a&gt;" alt="&lt;a&gt;test&lt;/a&gt;" title="&lt;a&gt;test2&lt;/a&gt;" /></p>'

    >>> render("**bold** ''italic'' ~~strikeout~~")
    '<p><strong>bold</strong> <em>italic</em> <del>strikeout</del></p>'

    >>> render("this is ``a red on yellow text``:c[#FF0000:#FFFF00]")
    '<p>this is <span style="color: #FF0000;background-color: #FFFF00;">a red on yellow text</span></p>'

    >>> render("this is ``a text with yellow background``:c[:yellow]")
    '<p>this is <span style="background-color: yellow;">a text with yellow background</span></p>'

    >>> render("this is ``a colored text (RoyalBlue)``:color[rgb(65,105,225)]")
    '<p>this is <span style="color: rgb(65,105,225);">a colored text (RoyalBlue)</span></p>'

    >>> render("this is ``a green text``:color[green:]")
    '<p>this is <span style="color: green;">a green text</span></p>'

    >>> render("**@{probe:1}**", environment=dict(probe=lambda t:"test %s" % t))
    '<p><strong>test 1</strong></p>'

    >>> render("**@{probe:t=a}**", environment=dict(probe=lambda t:"test %s" % t, a=1))
    '<p><strong>test 1</strong></p>'

    >>> render('[[id1 [span **messag** in ''markmin''] ]] ... [[**link** to id [link\'s title] #mark1]]')
    '<p><span class="anchor" id="markmin_id1">span <strong>messag</strong> in markmin</span> ... <a href="#markmin_mark1" title="link\'s title"><strong>link</strong> to id</a></p>'

    >>> render('# Multiline[[NEWLINE]]\n title\nParagraph[[NEWLINE]]\nwith breaks[[NEWLINE]]\nin it')
    '<h1>Multiline<br /> title</h1><p>Paragraph<br /> with breaks<br /> in it</p>'

    >>> render("anchor with name 'NEWLINE': [[NEWLINE [ ] ]]")
    '<p>anchor with name \'NEWLINE\': <span class="anchor" id="markmin_NEWLINE"></span></p>'

    >>> render("anchor with name 'NEWLINE': [[NEWLINE [newline] ]]")
    '<p>anchor with name \'NEWLINE\': <span class="anchor" id="markmin_NEWLINE">newline</span></p>'
    R{   s   
RZ   t   utf8c         S   s   |  j  d ƒ j t ƒ S(   Ni   (   RM   t	   translatet   ttab_in(   RO   (    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyRP   ¦  s    s   s   
Rz   s   ``\g<latex>``:latex c      	      s÷   |  j  d ƒ } | t t f k rD ˆ j d  d  d  | f ƒ |  j  ƒ  S| d k rg ˆ j d
 ƒ |  j  ƒ  S|  j  d ƒ py d } |  j  d ƒ pŽ d } d ˆ  k r¶ | ˆ  d k r¶ d } n  |  j  d ƒ j d d	 ƒ } ˆ j | | | |  j  d ƒ f ƒ t S(   Ni    s   ````RZ   RW   Ry   t   codet   ts   !`!t   `(   NNNRZ   (   RM   t   METAt   DISABLED_METAt   appendR   RN   (   RO   t   gRW   Ry   R€   (   t   allowedt   segments(    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt	   mark_code´  s    

 	"c            s2   ˆ  j  |  j ƒ  t k r d  n |  j d ƒ ƒ t S(   NR(   (   R…   RM   t   LINKR   (   RO   (   t   links(    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt	   mark_linkÊ  s    c            s   ˆ  |  j  d d ƒ Œ  S(   NRy   R"   (   RM   (   RO   (   t
   protolinks(    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyRP   Ò  s    c            su   t  t |  ƒ ƒ } ˆ j ˆ  d  d  d … ƒ ˆ j d | | f ƒ d | ˆ f g ˆ  (d } g  ˆ (g  ˆ (| d f S(   Niÿÿÿÿs   <h%s>%ss   </h%s>%si    t   h(   Rg   t   lent   extendR…   (   R   R(   t   hlevelt   lev(   t   etagst   ltagst   outt   ppt   tlev(    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   parse_titleÜ  s    c   	         sÛ  t  |  ƒ } | | k  r_ x1 ˆ d | k rK ˆ j ƒ  ˆ j ˆ  j ƒ  ƒ q W| } g  ˆ | )n  | | k rO| d k r© ˆ j ˆ  d  d  d … ƒ g  ˆ (g  ˆ (g  ˆ  (n  ˆ rÛ | d k rÛ ˆ j ˆ  j ƒ  ƒ ˆ j ƒ  n  xNt | | ƒ D]\ } ˆ j d | d ˆ ƒ ˆ  j d | d ˆ ƒ | d 7} ˆ j | ƒ ˆ j | ƒ qì WnÝ | | k r,ˆ d | k rôx: t ˆ j | ƒ ƒ D]# } ˆ j ƒ  ˆ j ˆ  j ƒ  ƒ qW| ˆ d <ˆ j d | d ˆ ƒ ˆ  j d | d ˆ ƒ ˆ j | ƒ q,ˆ j | ƒ d k r,ˆ j ˆ  j ƒ  ƒ ˆ j ƒ  q,n  d } ˆ j d	 ƒ ˆ  j d
 ˆ ƒ ˆ j | ƒ | d  d k r‹ˆ | | | ƒ \ } } } n  | rÁ| d k rÁˆ |  | | d | ƒ \ } } } n ˆ j | ƒ | | | f S(   Niÿÿÿÿi    t   .t   <t   >s   </i   t   ls   <li>s   </li>t   -RZ   (   R   t   popR…   R   t   xranget   count(	   R   Ry   R(   t   tagR’   t   mtagt   linenot   lentt   i(   R“   R”   R•   t   parse_pointt   parse_table_or_blockquotet   pendR–   R—   (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt
   parse_listæ  sX    




$c            s’  t  |  ƒ } | | k r4 ˆ |  d | d | | | ƒ S| | k  r x1 ˆ d | k rs ˆ j ƒ  ˆ j ˆ j ƒ  ƒ qC W| } g  ˆ | )d } nA | | k rÎ ˆ rÎ | d k rÎ ˆ j ˆ j ƒ  ƒ ˆ j ƒ  qÎ n  ˆ  rð | d k rð ˆ j ˆ  ƒ n  | t k rd } ns d } | d  d k r9ˆ | | | ƒ \ } } } n  | d k rxˆ j ˆ ƒ ˆ rxˆ j ˆ ƒ ˆ j | ƒ qxn  ˆ j | ƒ | | | f S(	   s    paragraphs in lists R™   t   uliÿÿÿÿRZ   Rœ   i   R   (   Rœ   R™   (   R   Rž   R…   Rƒ   (   R   R(   R’   R¢   R£   R¤   (	   t   brR“   R”   R•   R©   R§   t   pbegR¨   R—   (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyR¦     s8    

		c            s  | d ˆ k s> |  j  d ƒ t |  ƒ k o: t |  ƒ d k rK |  | | f S| d 7} ˆ | j ƒ  }  |  rõd |  k rYg  } g  } g  } d } d } d } x}| ˆ k  rˆ | j ƒ  }  |  d  d k r2|  j  d ƒ t |  ƒ k r2t |  ƒ d k r2| s| } n | j | ƒ g  } d } | d 7} qž q2n  t j |  ƒ }	 |	 ru|	 j d ƒ pYd } |	 j d	 ƒ pnd } Pn  | d
 rˆd }
 n | d k ršd n d }
 | j |
 d j g  |  j	 d ƒ D]1 } d t
 j | ƒ rÝd n d | j ƒ  f ^ q¿ƒ d ˆ ƒ | d 7} | d 7} qž W| r=| d k r=d ˆ  | f n d } | rYd ˆ | f n d } d }  | r¤|  d ˆ d j g  | D] } | ^ q‚ƒ d ˆ 7}  n  | s¹| } g  } n  | rø|  d ˆ d j g  | D] } | ^ qÖƒ d ˆ 7}  n  | r7|  d ˆ d j g  | D] } | ^ qƒ d ˆ 7}  n  d | | ˆ |  ˆ f }  d } q| } t } d } d } x| ˆ k  rˆ | j ƒ  }  | sOt j |  ƒ }	 |	 r | d ˆ k sÏd ˆ | d k r |	 j d ƒ pád } |	 j d	 ƒ pöd } Pq n  t j |  ƒ rt| d ˆ k  r<ˆ | d j ƒ  r<t } n  | d 7} qtqtn% t j |  ƒ rtt } | d 7} qtn  | d 7} qtW| r¤| d k r¤d ˆ  | f n d } | rÀd ˆ | f n d } d | | d j ˆ | | !ƒ ˆ f }  d } n d }  | d 8} d } |  d | f S(    Ni   R   i   R   i    RZ   t   =RW   Ry   i   s   <tr class="even">s   <tr class="first">s   <tr>s   <td%s>%s</td>s    class="num"s   </tr>R7   s    class="%s%s"s
    id="%s%s"s   <thead>s   </thead>s   <tbody>s   </tbody>s   <tfoot>s   </tfoot>s   <table%s%s>%s%s</table>%sR   s!   <blockquote%s%s>%s</blockquote>%ss   
t   qs   <hr />(   R    R   t   stripR   t   regex_tqR_   RM   R…   t   joinR^   t	   regex_numR   t   regex_bq_headlineR   (   R(   R¢   R£   t   toutt   theadt   tbodyt   rownumt   t_idt   t_clsRO   t   trRX   Rœ   t   bq_begint   t_mode(   t   class_prefixt	   id_prefixR–   t   stringst   strings_len(    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyR§   9  s¬    .
-	
	
	]
(9	99		
	
(	
Ry   s   <p>s   </p>R«   s   <br />i    i   s   #+-.t   #t   +t   olR   Rª   R®   t    s   	NiÿÿÿÿR™   s   <strong>\g<t></strong>s   <del>\g<t></del>s   <em>\g<t></em>c            s)  |  j  d d d d d ƒ \ } } } } } | s= |  j  d ƒ St | ƒ } | pR d } | re d | n d } | r d	 t | ƒ j t t ƒ n d } d } }	 | d
 k r¼ d } d ˆ }	 nk | d k rÛ d } d ˆ }	 nL | d k rú d } d ˆ }	 n- | d# k r'd | | rd | n d } n  | r]t j | ƒ r]| d | } d |	 }	 d } n  | rpd | } n  | d$ k rÒt | i  i  d ˆ  ˆ ˆ ˆ ˆ ˆ ˆ ˆ ƒ } d t d | d | d | d | d | ƒ S| rôd t | ƒ j t t ƒ n d }
 d t d  | d | d! |
 d | d | d" |	 ƒ S(%   NR   RV   R"   Ry   t   wi    RZ   s   width:%ss    title="%s"t   centers   <p style="text-align:center">s   </p>t	   blocklefts   <p style="text-align:left">t
   blockrights   <p style="text-align:right">R>   R<   s   float:%ss   ;%ss   <a href="%s">s   </a>s    style="%s"t   videot   audioR«   sP   <%(p)s controls="controls"%(title)s%(style)s><source src="%(k)s" />%(t)s</%(p)s>t   titlet   styles	    alt="%s"s<   %(begin)s<img src="%(k)s"%(alt)s%(title)s%(style)s />%(end)st   begint   altt   end(   s   lefts   right(   RÉ   RÊ   (	   RM   R    RN   Rƒ   R„   RT   R_   R   R2   (   RO   R   RV   R"   Ry   RÅ   RÌ   RË   t   p_begint   p_endRÎ   (	   t   URLRS   R½   t   environmentR¾   t   latexR–   t   pretty_printR   (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt	   sub_media  sB    *(
!
	&(c            s£  |  j  d d d d ƒ \ } } } } | r? | r? |  j  d ƒ S| pH d } | r] t | ƒ n d } | rId | k r§ d | j d ƒ d k r§ | j d d ˆ ƒ } n  t | ƒ } | rÏ d	 | j t t ƒ n d } | d
 k rç d n d } | r t | i  i  d ˆ  ˆ ˆ d  d  ˆ ˆ ˆ ƒ n | } d t d | d | d | d | ƒ S| d k rd| rdd ˆ Sd t ˆ | ƒ t | i  i  d ˆ  ˆ ˆ ˆ ˆ ˆ ˆ ˆ ƒ f S(   NR   RV   R"   Ry   i    RZ   RÁ   Rt   s    title="%s"t   popups    target="_blank"R«   s,   <a href="%(k)s"%(title)s%(target)s>%(t)s</a>RË   t   targett   NEWLINEs   <br />s&   <span class="anchor" id="%s">%s</span>(	   RM   R    R^   RN   Rƒ   R„   R   R   R2   (   RO   R   RV   R"   Ry   RË   RØ   (	   RÒ   RS   R½   RÓ   R¾   RÔ   R–   RÕ   R   (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   sub_link4  s,    $%"9 	s   [[%s]]c            sÄ  ˆ j  d ƒ \ } ‰  } } | d  k s9 |  j ƒ  t k rC t | ƒ Sˆ  ˆ k r½ | d  d k rl | d } n  | d d k r‰ | d  } n  | r¦ t ˆ ˆ  | | ƒ ƒ St ˆ ˆ  | ƒ ƒ SnHˆ  d k r d d j ‡  ‡ f d †  t | ƒ j d ƒ Dƒ ƒ d	 Sˆ  d
 k rt t	 j
 | ƒ Sˆ  t k r^d ˆ  t | i  i  d ˆ ˆ ˆ ˆ ˆ
 ˆ ˆ ˆ	 ƒ f Sˆ  d k r| r| j d ƒ } | d r—d | d n d } t | ƒ d k rÇ| d rÇd | d n d } d | | t | i  i  d ˆ ˆ ˆ ˆ ˆ
 ˆ ˆ ˆ	 ƒ f Sˆ  r'ˆ  d k r'd ˆ ˆ  f n d } | rId ˆ t | ƒ f n d } | d  d k }	 d  d g | d d k }
 |	 r¦|
 r¦d | | t | d d !ƒ ˆ f Sd | | t | |	 |
 !ƒ f S(   Ni    i   s   
iÿÿÿÿt   citet   [t   ,c         3   s&   |  ] } d  ˆ | ˆ  | f Vq d S(   s   <a href="#%s" class="%s">%s</a>N(    (   R!   t   d(   R   R¾   (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pys	   <genexpr>k  s   t   ]RÔ   s!   <span style="color: %s">%s</span>R«   RW   t   colorRt   s
   color: %s;RZ   s   background-color: %s;s   <span style="%s%s">%s</span>R7   s    class="%s%s"s
    id="%s%s"s    <pre><code%s%s>%s</code></pre>%ss   <code%s%s>%s</code>(   RW   Rà   (   Rž   R   RM   R„   R    Rg   R±   R^   t   LATEXt   urllibt   quotet   html_colorsR   R   (   RO   R€   Ry   R(   RW   t   fgt   bgt   clsR7   t   begRÏ   (   RÒ   RS   R½   RÓ   t   extraR¾   RÔ   R–   RÕ   R   Rˆ   (   R   sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   expand_meta_  sB    
  70("!(   RÄ   s   	(&   Rp   Rv   R%   t   unicodet   encodeRg   t   regex_backslashR   RN   R   Rc   t   regex_ddt
   regex_codet
   regex_linkR    t   regex_protoRU   R^   R   R¯   t
   regex_listt   findallRƒ   R   R…   Rž   R±   t   regex_strongt	   regex_delt   regex_emRŠ   t	   enumeratet   regex_media_level2t   regex_link_level2t   regex_expand_metaRk   R~   t   ttab_out(    RR   Ré   R‡   t   sepRÒ   RÓ   RÔ   RS   R   R½   R¾   RÕ   R‰   RŒ   R˜   R’   t   c0R¢   R£   t   s0R(   t   pc0t   t1t   t2Ry   t   ssRÖ   RÚ   t   partsR¥   t   htmlRê   (    (   RÒ   R‡   RS   R«   R½   RÓ   R“   Ré   R¾   RÔ   R‹   R”   R•   R©   R¦   R§   R¬   R¨   R–   RÕ   R   Rˆ   R¿   RÀ   R—   sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyR   ©  sî    ÷ 	 	
$3' u
	


'
'
!
$	$  	$
	'#'
	-#c	   	      C   s1   t  |  | | | d | d | d | d | d | ƒS(   NRS   R   R½   R¾   RÕ   (   R   (	   RR   Ré   R‡   Rü   RS   R   R½   R¾   RÕ   (    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyR   Š  s    c          C   s   d d  l  }  |  j ƒ  d  S(   Niÿÿÿÿ(   t   doctestt   testmod(   R  (    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   run_doctests’  s    t   __main__(   t   dedentsO  
         <!doctype html>
         <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
         <head>
         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
         %(style)s
         <title>%(title)s</title>
         </head>
         <body>
         %(body)s
         </body>
         </html>i   i   s   -hsâ  
              <style>
                blockquote { background-color: #FFFAAE; padding: 7px; }
                table { border-collapse: collapse; }
                thead td { border-bottom: 1px solid; }
                tfoot td { border-top: 1px solid; }
                .tableclass1 { background-color: lime; }
                .tableclass1 thead { color: yellow; background-color: green; }
                .tableclass1 tfoot { color: yellow; background-color: green; }
                .tableclass1 .even td { background-color: #80FF7F; }
                .tableclass1 .first td {border-top: 1px solid; }

                td.num { text-align: right; }
                pre { background-color: #E0E0E0; padding: 5px; }
              </style>RË   s   Markmin markup languageRÌ   RI   RÕ   s   -t(   t   Timeriè  s   markmin2html(__doc__)s%   from markmin2html import markmin2htmls   timeit "markmin2html(__doc__)":i   s%   %s loops, best of 3: %.3f ms per loopt   rRl   s   <link rel="stylesheet" href="s   "/>s   <style>
s   </style>s   Usage: i    s/    -h | -t | file.markmin [file.css|@path_to/css]s   where: -h  - print __doc__s6          -t  - timeit __doc__ (for testing purpuse only)sU          file.markmin  [file.css] - process file.markmin + built in file.css (optional)sX          file.markmin  [@path_to/css] - process file.markmin + link path_to/css (optional)(U   t   reRâ   t   cgiR    t   stringR   R&   R   RG   t   ImportErrort   compilert   compiler.astt   __all__t   __doc__Rä   Rƒ   RŠ   R„   Rá   t   compileRb   Rj   Rú   Rî   t   SRï   Rô   Rõ   Rö   R²   Rò   R³   R°   t   MRñ   RT   Rð   Rù   Rø   RQ   Rí   R   Rû   R   R   RL   R   RU   Rc   Rk   Rp   Rv   Rx   R   R   R   R   R  t   __name__t   sysR  t   textwrapR	  R  t   argvRÌ   R2   R   t   timeitR
  t   loopst   tst   mint   rangeR¥   R   R   t   opent   fargvt   readt   markmin_textt
   startswitht   markmin_stylet   fargv2t   close(    (    (    sL   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/markmin/markmin2html.pyt   <module>   sÖ   ÿ ô%		+							ÿ ÿ Ø		.