53
53
dl_rule = ur"^\s+.*?::\s"
55
55
# the big, fat, ugly one ;)
56
formatting_rules = ur"""(?P<ent_numeric>&#\d{1,5};)
56
formatting_rules = ur"""(?P<ent_numeric>&#(\d{1,5}|x[0-9a-fA-F]+);)
57
57
(?:(?P<emph_ibb>'''''(?=[^']+'''))
58
58
(?P<emph_ibi>'''''(?=[^']+''))
59
59
(?P<emph_ib_or_bi>'{5}(?=[^']))
83
85
(?P<email>[-\w._+]+\@[\w-]+(\.[\w-]+)+)
84
86
(?P<smiley>(?<=\s)(%(smiley)s)(?=\s))
85
87
(?P<smileyA>^(%(smiley)s)(?=\s))
88
(?P<ent_symbolic>&[a-zA-Z]+;)
87
90
(?P<wikiname_bracket>\[".*?"\])
88
91
(?P<tt_bt>`.*?`)""" % {
96
99
'smiley': u'|'.join(map(re.escape, config.smileys.keys()))}
98
101
# Don't start p before these
99
no_new_p_before = ("heading rule table tableZ tr td ul ol dl dt dd li "
100
"processor macro pre")
101
no_new_p_before = dict(zip(no_new_p_before.split(), [1] * len(no_new_p_before)))
102
no_new_p_before = ("heading rule table tableZ tr td "
103
"ul ol dl dt dd li li_none indent "
104
"macro processor pre")
105
no_new_p_before = no_new_p_before.split()
106
no_new_p_before = dict(zip(no_new_p_before, [1] * len(no_new_p_before)))
103
108
def __init__(self, raw, request, **kw):
423
428
return self.attachment(words, pretty_url=1)
425
430
if wikiutil.isPicture(words[1]) and re.match(self.url_rule, words[1]):
426
return (self.formatter.url(1, words[0], css='external', unescaped=1) +
431
return (self.formatter.url(1, words[0], css='external', do_escape=0) +
427
432
self.formatter.image(title=words[0], alt=words[0], src=words[1]) +
428
433
self.formatter.url(0))
430
return (self.formatter.url(1, words[0], css='www', unescaped=1) +
435
return (self.formatter.url(1, words[0], css=scheme, do_escape=0) +
431
436
self.formatter.text(words[1]) +
432
437
self.formatter.url(0))
447
452
# '>': '>'}[word]
450
454
def _ent_numeric_repl(self, word):
451
"""Handle numeric SGML entities."""
452
return self.formatter.rawHTML(word)
455
"""Handle numeric (decimal and hexadecimal) SGML entities."""
456
return self.formatter.rawHTML(word)
458
def _ent_symbolic_repl(self, word):
459
"""Handle symbolic SGML entities."""
460
return self.formatter.rawHTML(word)
462
def _indent_repl(self, match):
463
"""Handle pure indentation (no - * 1. markup)."""
466
self._close_item(result)
469
if self.line_was_empty and not self.first_list_item:
471
result.append(self.formatter.listitem(1, css_class=css_class, style="list-style-type:none"))
472
return ''.join(result)
474
def _li_none_repl(self, match):
475
"""Handle type=none (" .") lists."""
477
self._close_item(result)
480
if self.line_was_empty and not self.first_list_item:
482
result.append(self.formatter.listitem(1, css_class=css_class, style="list-style-type:none"))
483
return ''.join(result)
455
485
def _li_repl(self, match):
456
"""Handle bullet lists."""
486
"""Handle bullet (" *") lists."""
458
indented_only = (match == (" " * len(match)))
459
if indented_only and self.in_li:
462
488
self._close_item(result)
466
491
if self.line_was_empty and not self.first_list_item:
467
492
css_class = 'gap'
469
result.append(self.formatter.listitem(1, css_class=css_class,
470
style="list-style-type:none"))
472
result.append(self.formatter.listitem(1, css_class=css_class))
474
## result.append(self.formatter.paragraph(1))
493
result.append(self.formatter.listitem(1, css_class=css_class))
475
494
return ''.join(result)
478
496
def _ol_repl(self, match):
479
497
"""Handle numbered lists."""
480
498
return self._li_repl(match)
516
534
# self.inhibit_p = 1
518
536
# Close lists while char-wise indent is greater than the current one
519
while ((self._indent_level() > new_level) or
521
(self._indent_level() == new_level) and
522
(self.list_types[-1]) != list_type)):
537
#while ((self._indent_level() > new_level) or
539
# (self._indent_level() == new_level) and
540
# (self.list_types[-1]) != list_type)):
541
while self._indent_level() > new_level:
523
542
self._close_item(close)
524
543
if self.list_types[-1] == 'ol':
525
544
tag = self.formatter.number_list(0)
672
692
'arg': arg, 'key': key}
674
694
attrs['bgcolor'] = '"#%s"' % arg
676
arg = parser.get_token()
677
this_key = attrdef.split('=')[0]
678
attrs[this_key] = arg
681
697
#print "key: %s\nattrs: %s" % (key, str(attrs))
682
698
return self.formatter.rawHTML(msg)
825
841
def _macro_repl(self, word):
826
842
"""Handle macros ([[macroname]])."""
827
843
macro_name = word[2:-2]
828
#self.inhibit_p = 1 # fixes UserPreferences, but makes new trouble!
844
self.inhibit_p = 1 # 0 fixes UserPreferences, but makes new trouble!
830
846
# check for arguments
856
872
###result.append(u'<span class="info">[add text before match: <tt>"%s"</tt>]</span>' % line[lastpos:match.start()])
858
874
if not (self.inhibit_p or self.in_pre or self.formatter.in_p):
859
result.append(self.formatter.paragraph(1))
875
result.append(self.formatter.paragraph(1, css_class="line879"))
860
876
result.append(self.formatter.text(line[lastpos:match.start()]))
862
878
# Replace match with markup
868
884
# No match: Add paragraph with the text of the line
869
885
if not (self.in_pre or self.inhibit_p or
870
886
self.formatter.in_p) and lastpos < len(line):
871
result.append(self.formatter.paragraph(1))
887
result.append(self.formatter.paragraph(1, css_class="line886"))
872
888
result.append(self.formatter.text(line[lastpos:]))
873
889
return u''.join(result)
885
901
# Open p for certain types
886
902
if not (self.inhibit_p or self.formatter.in_p
887
903
or self.in_pre or (type in self.no_new_p_before)):
888
result.append(self.formatter.paragraph(1))
904
result.append(self.formatter.paragraph(1, css_class="line903"))
890
906
# Get replace method and replece hit
891
907
replace = getattr(self, '_' + type + '_repl')
998
1014
self.processor = None
1000
1016
# send rest of line through regex machinery
1001
line = line[endpos+3:]
1017
line = line[endpos+3:]
1018
if not line.strip(): # just in the case "}}} " when we only have blanks left...
1003
1021
# we don't have \n as whitespace any more
1004
1022
# This is the space between lines we join to one paragraph
1042
1060
# output proper indentation tags
1043
self.request.write(self._indent_to(indlen, indtype, numtype,
1061
self.request.write(self._indent_to(indlen, indtype, numtype, numstart))
1047
1064
# TODO: move into function?
1049
1066
and line[-3:] == "|| " and len(line) >= 5 + indlen):
1051
1068
if self.list_types and not self.in_li:
1052
self.request.write(self.formatter.listitem
1053
(1, style="list-style-type:none"))
1069
self.request.write(self.formatter.listitem(1, style="list-style-type:none"))
1054
1070
## CHANGE: no automatic p on li
1055
1071
##self.request.write(self.formatter.paragraph(1))
1077
1093
formatted_line = self.scan(scan_re, line)
1078
1094
self.request.write(formatted_line)
1096
if self.in_pre == 3:
1081
1097
self.request.write(self.formatter.linebreak())
1083
1099
# Close code displays, paragraphs, tables and open lists