Changeset 1761

Show
Ignore:
Timestamp:
09/11/08 11:38:30 (18 months ago)
Author:
JensDiemer
Message:

-patch the creole markup, so it don't clashes with django template tags.
-Add a unitest and merge some parts from the tinxTextile markup test.

Location:
trunk/pylucid_project
Files:
2 added
3 modified
1 moved

Legend:

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

    r1651 r1761  
    1515<hr /> 
    1616 
     17<p>Please note:<br /> 
     18The Creole <b>image tag is more strict than the original</b>, 
     19because it should not match on django template tags!<br /> 
     20It matches only if... 
     21</p> 
     22<ol> 
     23    <li>...image target ends with a picture extention</li> 
     24    <li>...separator &gt;|&lt; and the image text exist</li> 
     25</ol> 
     26 
     27 
     28<hr /> 
     29 
    1730<h2 class="noanchor">Usefull links:</h2> 
    1831<ul id="links"> 
  • trunk/pylucid_project/PyLucid/system/markups/creole.py

    r1634 r1761  
    4444            ]] 
    4545        )''' 
     46 
     47    #--------------------------------------------------------------------------     
     48    # PyLucid Patch: 
     49    # The image rule should not match on django template tags! So we make it 
     50    # more restricted. 
     51    # It matches only if... 
     52    # ...image target ends with a picture extention 
     53    # ...separator >|< and the image text exist 
    4654    image = r'''(?P<image> 
    4755            {{ 
    48             (?P<image_target>.+?) \s* 
    49             ([|] \s* (?P<image_text>.+?) \s*)? 
     56            (?P<image_target>.+?\.jpg|\.jpeg|\.gif|\.png) \s* 
     57            (\| \s* (?P<image_text>.+?) \s*)? 
    5058            }} 
    51         )''' 
     59        )(?i)''' 
     60    #-------------------------------------------------------------------------- 
     61 
    5262    macro = r'''(?P<macro> 
    5363            << 
  • trunk/pylucid_project/PyLucid/system/markups/creole2html.py

    r1634 r1761  
    184184 
    185185if __name__=="__main__": 
    186     #~ import sys 
    187     #~ document = Parser(unicode(sys.stdin.read(), 'utf-8', 'ignore')).parse() 
    188     #~ sys.stdout.write(HtmlEmitter(document).emit().encode('utf-8', 'ignore')) 
    189  
    190186    """ 
    191187    http://code.google.com/p/creoleparser/source/browse/trunk/creoleparser/tests.py 
     
    194190    http://djikiki.googlecode.com/svn/trunk/djikiki/creole/ 
    195191    """ 
    196  
    197     test1 = u""" 
    198 == Textauszeichnung 
    199  
    200 Das ist **fett** und //kursiv//. 
    201 Und noch eine Zeile... 
    202  
    203 == Links 
    204  
    205 Ein [[Interner Link ]] und ein normaler Link: 
    206 [[http://domain.tld/page/| Link Text]] 
    207  
    208 ---- 
    209  
    210 Bilder mit {{Image.jpg|Ein Bild}} toll. 
    211  
    212 Eine Liste: 
    213  * eins 
    214  * zwei 
    215  ** drei 
    216  ### Nummer 1 
    217  ### Nummer 2 
    218  
    219 == Tabelle 
    220  
    221   |= Item|= Size|= Price | 
    222   | fish | **big**  |cheap   | 
    223   | crab | small|expesive| 
    224  
    225   |= Item|= Size|= Price 
    226   | fish | big  |//cheap// 
    227   | crab | small|**very\\expesive** 
    228  
    229 == preformatted 
    230  
    231 {{{ 
    232 == [[NoWiki]]: 
    233 //**don't** format// 
    234  
    235 Good work! 
    236 }}}""" 
    237  
    238  
    239     test2 = u"""= Top-level heading (1) 
    240 == This a test for creole 0.1 (2) 
    241 === This is a Subheading (3) 
    242 ==== Subsub (4) 
    243 ===== Subsubsub (5) 
    244  
    245 The ending equal signs should not be displayed: 
    246  
    247 = Top-level heading (1) = 
    248 == This a test for creole 0.1 (2) == 
    249 === This is a Subheading (3) === 
    250 ==== Subsub (4) ==== 
    251 ===== Subsubsub (5) ===== 
    252  
    253  
    254 You can make things **bold** or //italic// or **//both//** or //**both**//. 
    255  
    256 Character formatting extends across line breaks: **bold, 
    257 this is still bold. This line deliberately does not end in star-star. 
    258  
    259 Not bold. Character formatting does not cross paragraph boundaries. 
    260  
    261 You can use [[internal links]] or [[http://www.wikicreole.org|external links]], 
    262 give the link a [[internal links|different]] name. 
    263  
    264 Here's another sentence: This wisdom is taken from [[Ward Cunningham's]] 
    265 [[http://www.c2.com/doc/wikisym/WikiSym2006.pdf|Presentation at the Wikisym 06]]. 
    266  
    267 Here's a external link without a description: [[http://www.wikicreole.org]] 
    268  
    269 Be careful that italic links are rendered properly:  //[[http://my.book.example/|My Book Title]]//  
    270  
    271 Free links without braces should be rendered as well, like http://www.wikicreole.org/ and http://www.wikicreole.org/users/~example.  
    272  
    273 Creole1.0 specifies that http://bar and ftp://bar should not render italic, 
    274 something like foo://bar should render as italic. 
    275  
    276 You can use this to draw a line to separate the page: 
    277 ---- 
    278  
    279 You can use lists, start it at the first column for now, please... 
    280  
    281 unnumbered lists are like 
    282 * item a 
    283 * item b 
    284 * **bold item c** 
    285  
    286 blank space is also permitted before lists like: 
    287   *   item a 
    288  * item b 
    289 * item c 
    290  ** item c.a 
    291  
    292 or you can number them 
    293 # [[item 1]] 
    294 # item 2 
    295 # // italic item 3 // 
    296     ## item 3.1 
    297   ## item 3.2 
    298  
    299 up to five levels 
    300 * 1 
    301 ** 2 
    302 *** 3 
    303 **** 4 
    304 ***** 5 
    305  
    306 * You can have 
    307 multiline list items 
    308 * this is a second multiline 
    309 list item 
    310  
    311 You can use nowiki syntax if you would like do stuff like this: 
    312  
    313 {{{ 
    314 Guitar Chord C: 
    315  
    316 ||---|---|---| 
    317 ||-0-|---|---| 
    318 ||---|---|---| 
    319 ||---|-0-|---| 
    320 ||---|---|-0-| 
    321 ||---|---|---| 
    322 }}} 
    323  
    324 Note: if you look at the source code of the above, you see the escape char (tilde, ~ ) 
    325 being used to escape the closing triple curly braces. This is to do nowiki nesting in this 
    326 wiki which doesn't follow Creole 1.0 yet (closing triple curly braces should be indented 
    327 by one space). 
    328  
    329 You can also use it inline nowiki {{{ in a sentence }}} like this. 
    330  
    331 !!! Escapes  
    332 Normal Link: http://wikicreole.org/ - now same link, but escaped: ~http://wikicreole.org/  
    333  
    334 Normal asterisks: ~**not bold~** 
    335  
    336 a tilde alone: ~ 
    337  
    338 a tilde escapes itself: ~~xxx 
    339  
    340 !! Creole 0.2  
    341  
    342 This should be a flower with the ALT text "this is a flower" if your wiki supports ALT text on images: 
    343  
    344 [{ImagePro src='Red-Flower.jpg' caption='here is a red flower' }] 
    345  
    346 !! Creole 0.4  
    347  
    348 Tables are done like this: 
    349  
    350 ||header col1||header col2 
    351 |col1|col2 
    352 |you         |can          
    353 |also        |align\\ it.  
    354  
    355 You can format an address by simply forcing linebreaks: 
    356  
    357 My contact dates:\\ 
    358 Pone: xyz\\ 
    359 Fax: +45\\ 
    360 Mobile: abc 
    361  
    362 !! Creole 0.5  
    363  
    364 || Header title               || Another header title      
    365 | {{{ //not italic text// }}} | {{{ **not bold text** }}}  
    366 | ''italic text''             | __  bold text __           
    367  
    368 !! Creole 1.0  
    369  
    370 If interwiki links are setup in your wiki, this links to the WikiCreole page about Creole 1.0 test cases: [WikiCreole:Creole1.0TestCases]. 
     192     
     193    txt = """ 
     194== Headline 
     195 
     196This is **bold**... 
     197Wow... 
     198 
     199The current page name: >{{ PAGE.name }}< great? 
     200Some {% lucidTag page_update_list count=10 %} text. 
     201 
     202a [[www.google.de|Google]] link 
     203a ((/image.jpg|My Image)) image 
     204a {{/image.jpg|My Image}} image 
     205 
     206no image: {{ foo|bar }}! 
     207A picture [[http://google.com | {{ campfire.JPG | campfire.jpg }} ]] as a link. 
    371208 
    372209""" 
    373210 
    374     document = Parser(test2).parse() 
     211    document = Parser(txt).parse() 
    375212    print HtmlEmitter(document).emit() 
    376  
    377  
  • trunk/pylucid_project/tests/markup_tinyTextile.py

    r1752 r1761  
    1717""" 
    1818 
    19 import sys, re, difflib, unittest, traceback 
     19import sys, re, unittest 
    2020 
    2121import tests 
    2222from tests.utils.FakeRequest import get_fake_context 
     23from tests.utils import unittest_addons 
    2324 
    2425from PyLucid.system.markups.tinyTextile import TinyTextileParser 
     
    3637VERBOSE = 2 
    3738 
     39unittest_addons.VERBOSE = VERBOSE 
    3840 
    3941#_____________________________________________________________________________ 
     
    4143 
    4244 
    43 class textileFailure(Exception): 
    44     """ 
    45     Special error class: Try to display markup errors in a better way. 
    46     """ 
    47     def _format_output(self, txt): 
    48         txt = txt.split("\\n") 
    49         if VERBOSE == 1: 
    50             txt = "".join(['%s\\n\n' % i for i in txt]) 
    51         elif VERBOSE == 2: 
    52             txt = "".join(['%s\n' % i for i in txt]) 
    53         return txt 
    54  
    55     def _diff(self, block1, block2): 
    56         d = difflib.Differ() 
    57  
    58         block1 = block1.replace("\\n", "\\n\n").split("\n") 
    59         block2 = block2.replace("\\n", "\\n\n").split("\n") 
    60  
    61         diff = d.compare(block1, block2) 
    62  
    63         result = ["%2s %s\n" % (line, i) for line, i in enumerate(diff)] 
    64         return "".join(result) 
    65  
    66     def __str__(self): 
    67         try: 
    68             msg = self.args[0] 
    69  
    70             # strip ' out 
    71             if msg.startswith("u'"): 
    72                 msg = msg[2:-1] 
    73             else: 
    74                 msg = msg[1:-1] 
    75  
    76             try: 
    77                 block1, block2 = msg.split("' != '") 
    78             except ValueError: 
    79                 msg = self._format_output(msg) 
    80                 return ( 
    81                     "Format error in output\n" 
    82                     "Info:\n%s" 
    83                 ) % msg 
    84  
    85             #~ block1 = block1.rstrip("\\n") 
    86             #~ block2 = block2.rstrip("\\n") 
    87             diff = self._diff(block1, block2) 
    88  
    89             block1 = self._format_output(block1) 
    90             block2 = self._format_output(block2) 
    91  
    92             return ( 
    93                 "\n\n---[Output:]---\n%s\n" 
    94                 "---[not equal to:]---\n%s" 
    95                 "\n---[diff:]---\n%s" 
    96             ) % (block1, block2, diff) 
    97         except: 
    98             etype, value, tb = sys.exc_info() 
    99             msg = traceback.format_exc(tb) 
    100             return msg 
    101  
    102  
    103 #_____________________________________________________________________________ 
    104  
    105  
    106  
    107 class tinyTextileTest(unittest.TestCase): 
    108  
    109     # Use the own error class from above 
    110     failureException = textileFailure 
     45class tinyTextileTest(unittest_addons.MarkupTest): 
    11146 
    11247    def setUp(self): 
     
    11853        """ delete the out buffer """ 
    11954        self.out.data = [] 
    120  
    121     #_________________________________________________________________________ 
    122  
    123     def _prepare_text(self, txt): 
    124         """ 
    125         prepare the multiline, indentation text. 
    126         """ 
    127         txt = txt.splitlines() 
    128         assert txt[0]=="", "First must be empty!" 
    129         txt = txt[1:] # Skip the first line 
    130  
    131         # get the indentation level from the first line 
    132         count = False 
    133         for count, char in enumerate(txt[0]): 
    134             if char!=" ": 
    135                 break 
    136  
    137         assert count != False, "second line is empty!" 
    138  
    139         # remove indentation from all lines 
    140         txt = [i[count:] for i in txt] 
    141  
    142         #~ txt = re.sub("\n {2,}", "\n", txt) 
    143         txt = "\n".join(txt) 
    144  
    145         # strip *one* newline at the begining... 
    146         if txt.startswith("\n"): txt = txt[1:] 
    147         # and strip *one* newline at the end of the text 
    148         if txt.endswith("\n"): txt = txt[:-1] 
    149         #~ print repr(txt) 
    150         #~ print "-"*79 
    151         return txt 
    15255 
    15356    #_________________________________________________________________________ 
     
    198101    #_________________________________________________________________________ 
    199102 
    200     def testSelf(self): 
    201         out1 = self._prepare_text(""" 
    202             one line 
    203             line two""") 
    204         self.assertEqual(out1, "one line\nline two") 
    205  
    206         out2 = self._prepare_text(""" 
    207             one line 
    208             line two 
    209         """) 
    210         self.assertEqual(out2, "one line\nline two") 
    211  
    212         out3 = self._prepare_text(""" 
    213             one line 
    214  
    215             line two 
    216         """) 
    217         self.assertEqual(out3, "one line\n\nline two") 
    218  
    219         out4 = self._prepare_text(""" 
    220             one line 
    221                 line two 
    222  
    223         """) 
    224         self.assertEqual(out4, "one line\n    line two\n") 
    225  
    226         out5 = self._prepare_text(""" 
    227             one line 
    228                 line two 
    229             dritte Zeile 
    230         """) 
    231         self.assertEqual(out5, "one line\n    line two\ndritte Zeile") 
    232  
    233     #_________________________________________________________________________ 
    234  
    235103    def testTextile_text1(self): 
    236104        out_string = self._parse("text") 
     
    239107    def testTextile_text2(self): 
    240108        self.assertTinyTextile(r""" 
    241             two lines\\in one line 
    242         """, """ 
    243             <p>two lines<br />in one line</p>\n 
     109            Force\\linebreak 
     110        """, """ 
     111            <p>Force<br />linebreak</p>\n 
    244112        """) 
    245113