Changeset 1769

Show
Ignore:
Timestamp:
09/16/08 13:31:56 (18 months ago)
Author:
JensDiemer
Message:
  • add a pass-through for normal django tags (not blocktags)
  • Move creole markup above
  • Update creole markup help and unittests
Location:
trunk/pylucid_project
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid_project/media/PyLucid/internal_page/page_admin/markup_help_creole.html

    r1766 r1769  
    3737    be interpreted as text, so every html characters would be escaped. 
    3838</li> 
     39<li><b>django tags/blocktags:</b><br /> 
     40    You can insert django tags and blocktags. No extra decoration is not needed. 
     41</li> 
    3942</ul> 
    4043 
  • trunk/pylucid_project/media/PyLucid/internal_page/page_admin/tag_list.html

    r1689 r1769  
    2020  </li> 
    2121{% endfor %} 
     22</ul> 
     23 
     24<h2 class="noanchor">Additional django template tags:</h2> 
     25<ul id="django_tags"> 
     26  <li> 
     27    <p> 
     28        Hightlight sourcecode via Pygments (if Pygments available): 
     29        &#x7B;% sourcecode py %&#x7D; 
     30        ... 
     31        &#x7B;% endsourcecode %&#x7D;<br /> 
     32        <strong>Note:</strong> Works only in html mode (without markup) correctly! 
     33    </p> 
     34  </li> 
    2235</ul> 
    2336 
  • trunk/pylucid_project/PyLucid/models/Page.py

    r1750 r1769  
    3030 
    3131MARKUPS = ( 
     32    (6, u'Creole wiki markup'), 
    3233    (0, u'html'), 
    3334    (1, u'html + TinyMCE'), 
     
    3637    (4, u'Markdown'), 
    3738    (5, u'ReStructuredText'), 
    38     (6, u'Creole wiki markup'), 
    3939) 
    4040 
  • trunk/pylucid_project/PyLucid/system/markups/creole.py

    r1766 r1769  
    5050            ]] 
    5151        )''' 
     52 
     53#    link = r'''(?P<link1> 
     54#            \[\[ 
     55#            (?P<link_target1>.+?)\|(?P<link_text1>.+?) 
     56#            ]] 
     57#        )|(?P<link2> 
     58#            \[\[ 
     59#            (?P<link_target2> (%s)://[^ ]+) \s* (?P<link_text2>.+?) 
     60#            ]] 
     61#        )| 
     62#            \[\[(?P<internal_link>.+)\]\] 
     63#        ''' % proto 
    5264 
    5365    #-------------------------------------------------------------------------- 
     
    113125 
    114126    # Pass-through all django template blocktags 
    115     passthrough = r'''^ \s*(?P<passthrough> 
     127    passthrough_block = r'''^ \s*(?P<passthrough_block> 
    116128            {%.*?%} 
    117129            (.|\n)+? 
     
    119131        ) \s*$ 
    120132        ''' 
     133    passthrough_line = r'''(?P<passthrough_line> 
     134            ({%.*?%})| 
     135            ({{.*?}}) 
     136        )''' 
    121137    #Pass-through html code lines 
    122138    html = r'''(?P<html> 
     
    141157    blockelements = ( 
    142158        "head", "list", "pre", "code", "table", "separator", "macro", 
    143         "passthrough", "html" 
     159        "passthrough_block", "html" 
    144160    ) 
    145161 
     
    161177    block_re = re.compile( 
    162178        '|'.join([ 
    163             Rules.passthrough, Rules.html, 
     179            Rules.passthrough_block, 
     180            Rules.html, 
    164181            Rules.line, Rules.head, Rules.separator, Rules.pre, Rules.list, 
    165182            Rules.table, Rules.text, 
     
    168185    ) 
    169186    # For inline elements: 
    170     inline_re = re.compile('|'.join([Rules.link, Rules.url, Rules.macro, 
    171         Rules.code, Rules.image, Rules.strong, Rules.emph, Rules.linebreak, 
    172         Rules.escape, Rules.char]), re.X | re.U) 
     187    inline_re = re.compile( 
     188        '|'.join([ 
     189            Rules.link, Rules.url, Rules.macro, 
     190            Rules.code, Rules.image, 
     191            Rules.passthrough_line, 
     192            Rules.strong, Rules.emph, Rules.linebreak, 
     193            Rules.escape, Rules.char 
     194        ]), 
     195        re.X | re.U 
     196    ) 
    173197 
    174198    def __init__(self, raw): 
     
    197221    # same method needs several names, because of group names in regexps. 
    198222 
    199     def _passthrough_repl(self, groups): 
     223    def _passthrough_block_repl(self, groups): 
    200224        """ Pass-through all django template blocktags """ 
    201225        self._upto_block() 
    202         DocNode("passthrough", self.root, groups["passthrough"]) 
     226        DocNode("passthrough_block", self.root, groups["passthrough_block"]) 
     227        self.text = None 
     228         
     229    def _passthrough_line_repl(self, groups): 
     230        """ Pass-through all django tags """ 
     231        DocNode("passthrough_line", self.cur, groups["passthrough_line"]) 
    203232        self.text = None 
    204233         
  • trunk/pylucid_project/PyLucid/system/markups/creole2html.py

    r1766 r1769  
    5858        print node 
    5959 
    60  
     60from PyLucid.tools.utils import escape 
    6161class HtmlEmitter: 
    6262    """ 
     
    8282 
    8383    def html_escape(self, text): 
    84         return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;') 
     84        return escape(text) 
     85        #return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;') 
    8586 
    8687    def attr_escape(self, text): 
     
    205206        return u"<pre>\n%s\n</pre>\n" % self.html_escape(node.content) 
    206207 
    207     def passthrough_emit(self, node): 
     208    def passthrough_block_emit(self, node): 
    208209        """ Pass-through all django template blocktags and html code lines """ 
    209210        return node.content + "\n" 
    210     html_emit = passthrough_emit 
     211    html_emit = passthrough_block_emit 
     212 
     213    def passthrough_line_emit(self, node): 
     214        """ Pass-through all django template tags """ 
     215        return node.content 
    211216 
    212217    def default_emit(self, node): 
  • trunk/pylucid_project/tests/markup_creole.py

    r1766 r1769  
    8484    #-------------------------------------------------------------------------- 
    8585 
    86     def test_creole_basic1(self): 
     86    def test_creole_basic(self): 
    8787        out_string = self._parse("a text line.") 
    8888        self.assertEqual(out_string, "<p>a text line.</p>\n") 
    8989 
    90     def test_creole_basic2(self): 
     90    def test_creole_linebreak(self): 
    9191        self.assertCreole(r""" 
    9292            Force\\linebreak 
     
    9696        """) 
    9797 
    98     def test_creole_basic3(self): 
    99         self.assertCreole(r""" 
    100             Here is [[a internal]] link. 
    101             This is [[http://domain.tld|external links]]. 
    102             A [[internal links|different]] link name. 
    103         """, """ 
    104             <p>Here is <a href="a internal">a internal</a> link.<br /> 
    105             This is <a href="http://domain.tld">external links</a>.<br /> 
    106             A <a href="internal links">different</a> link name.</p> 
    107         """) 
     98    def test_bold_italics(self): 
     99        self.assertCreole(r""" 
     100            **//bold italics//** 
     101            //**bold italics**// 
     102            //This is **also** good.// 
     103        """, """ 
     104            <p><strong><i>bold italics</i></strong><br /> 
     105            <i><strong>bold italics</strong></i><br /> 
     106            <i>This is <strong>also</strong> good.</i></p> 
     107        """) 
     108 
     109    def test_internal_links(self): 
     110        self.assertCreole(r""" 
     111            A [[internal]] link... 
     112            ...and [[/a internal]] link. 
     113        """, """ 
     114            <p>A <a href="internal">internal</a> link...<br /> 
     115            ...and <a href="/a internal">/a internal</a> link.</p> 
     116        """) 
     117         
     118    def test_external_links(self): 
     119        self.assertCreole(r""" 
     120            With pipe separator: 
     121            1 [[internal links|link A]] test. 
     122            2 [[http://domain.tld|link B]] test. 
     123        """, """ 
     124            <p>With pipe separator:<br /> 
     125            1 <a href="internal links">link A</a> test.<br /> 
     126            2 <a href="http://domain.tld">link B</a> test.</p> 
     127        """) 
     128 
     129    def test_bolditalic_links(self): 
     130        self.assertCreole(r""" 
     131            //[[a internal]]// 
     132            **[[Shortcut2|a page2]]** 
     133            //**[[Shortcut3|a page3]]**// 
     134        """, """ 
     135            <p><i><a href="a internal">a internal</a></i><br /> 
     136            <strong><a href="Shortcut2">a page2</a></strong><br /> 
     137            <i><strong><a href="Shortcut3">a page3</a></strong></i></p> 
     138        """) 
     139             
     140 
    108141 
    109142    def test_django1(self): 
     
    170203                if (x[i] &gt; 0) { 
    171204                  x[i]--; 
    172               }}} 
     205              &#x7D;&#x7D;} 
    173206            </pre> 
    174207        """) 
     
    217250            <a href="Link">Link</a><br /> 
    218251            [[Link]]</p> 
    219         """) 
    220  
    221     def test_bold_italics(self): 
    222         self.assertCreole(r""" 
    223             **//bold italics//** 
    224             //**bold italics**// 
    225             //This is **also** good.// 
    226              
    227             //[[a page|this is italic]]// 
    228             **[[a page]]** 
    229             //**[[a page]]**// 
    230         """, """ 
    231             <p><strong><i>bold italics</i></strong><br /> 
    232             <i><strong>bold italics</strong></i><br /> 
    233             <i>This is <strong>also</strong> good.</i></p> 
    234              
    235             <p><i><a href="a page">this is italic</a></i><br /> 
    236             <strong><a href="a page">a page</a></strong><br /> 
    237             <i><strong><a href="a page">a page</a></strong></i></p> 
    238252        """) 
    239253