Changeset 1761
- Timestamp:
- 09/11/08 11:38:30 (2 months ago)
- Location:
- trunk/pylucid_project
- Files:
-
- 2 added
- 3 modified
- 1 moved
-
media/PyLucid/internal_page/page_admin/markup_help_creole.html (modified) (1 diff)
-
PyLucid/system/markups/creole.py (modified) (1 diff)
-
PyLucid/system/markups/creole2html.py (modified) (2 diffs)
-
tests/markup_creole.py (added)
-
tests/markup_tinyTextile.py (moved) (moved from trunk/pylucid_project/tests/test_tinyTextile.py) (6 diffs)
-
tests/utils/unittest_addons.py (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid_project/media/PyLucid/internal_page/page_admin/markup_help_creole.html
r1651 r1761 15 15 <hr /> 16 16 17 <p>Please note:<br /> 18 The Creole <b>image tag is more strict than the original</b>, 19 because it should not match on django template tags!<br /> 20 It matches only if... 21 </p> 22 <ol> 23 <li>...image target ends with a picture extention</li> 24 <li>...separator >|< and the image text exist</li> 25 </ol> 26 27 28 <hr /> 29 17 30 <h2 class="noanchor">Usefull links:</h2> 18 31 <ul id="links"> -
trunk/pylucid_project/PyLucid/system/markups/creole.py
r1634 r1761 44 44 ]] 45 45 )''' 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 46 54 image = r'''(?P<image> 47 55 {{ 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*)? 50 58 }} 51 )''' 59 )(?i)''' 60 #-------------------------------------------------------------------------- 61 52 62 macro = r'''(?P<macro> 53 63 << -
trunk/pylucid_project/PyLucid/system/markups/creole2html.py
r1634 r1761 184 184 185 185 if __name__=="__main__": 186 #~ import sys187 #~ document = Parser(unicode(sys.stdin.read(), 'utf-8', 'ignore')).parse()188 #~ sys.stdout.write(HtmlEmitter(document).emit().encode('utf-8', 'ignore'))189 190 186 """ 191 187 http://code.google.com/p/creoleparser/source/browse/trunk/creoleparser/tests.py … … 194 190 http://djikiki.googlecode.com/svn/trunk/djikiki/creole/ 195 191 """ 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 196 This is **bold**... 197 Wow... 198 199 The current page name: >{{ PAGE.name }}< great? 200 Some {% lucidTag page_update_list count=10 %} text. 201 202 a [[www.google.de|Google]] link 203 a ((/image.jpg|My Image)) image 204 a {{/image.jpg|My Image}} image 205 206 no image: {{ foo|bar }}! 207 A picture [[http://google.com | {{ campfire.JPG | campfire.jpg }} ]] as a link. 371 208 372 209 """ 373 210 374 document = Parser(t est2).parse()211 document = Parser(txt).parse() 375 212 print HtmlEmitter(document).emit() 376 377 -
trunk/pylucid_project/tests/markup_tinyTextile.py
r1752 r1761 17 17 """ 18 18 19 import sys, re, difflib, unittest, traceback19 import sys, re, unittest 20 20 21 21 import tests 22 22 from tests.utils.FakeRequest import get_fake_context 23 from tests.utils import unittest_addons 23 24 24 25 from PyLucid.system.markups.tinyTextile import TinyTextileParser … … 36 37 VERBOSE = 2 37 38 39 unittest_addons.VERBOSE = VERBOSE 38 40 39 41 #_____________________________________________________________________________ … … 41 43 42 44 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 45 class tinyTextileTest(unittest_addons.MarkupTest): 111 46 112 47 def setUp(self): … … 118 53 """ delete the out buffer """ 119 54 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 line130 131 # get the indentation level from the first line132 count = False133 for count, char in enumerate(txt[0]):134 if char!=" ":135 break136 137 assert count != False, "second line is empty!"138 139 # remove indentation from all lines140 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 text148 if txt.endswith("\n"): txt = txt[:-1]149 #~ print repr(txt)150 #~ print "-"*79151 return txt152 55 153 56 #_________________________________________________________________________ … … 198 101 #_________________________________________________________________________ 199 102 200 def testSelf(self):201 out1 = self._prepare_text("""202 one line203 line two""")204 self.assertEqual(out1, "one line\nline two")205 206 out2 = self._prepare_text("""207 one line208 line two209 """)210 self.assertEqual(out2, "one line\nline two")211 212 out3 = self._prepare_text("""213 one line214 215 line two216 """)217 self.assertEqual(out3, "one line\n\nline two")218 219 out4 = self._prepare_text("""220 one line221 line two222 223 """)224 self.assertEqual(out4, "one line\n line two\n")225 226 out5 = self._prepare_text("""227 one line228 line two229 dritte Zeile230 """)231 self.assertEqual(out5, "one line\n line two\ndritte Zeile")232 233 #_________________________________________________________________________234 235 103 def testTextile_text1(self): 236 104 out_string = self._parse("text") … … 239 107 def testTextile_text2(self): 240 108 self.assertTinyTextile(r""" 241 two lines\\in one line242 """, """ 243 <p> two lines<br />in one line</p>\n109 Force\\linebreak 110 """, """ 111 <p>Force<br />linebreak</p>\n 244 112 """) 245 113
