添付ファイル 'meh.py'
ダウンロード 1 """
2 meh.py - small modification to the default wiki parser
3
4 Modified default wiki parser, which has:
5 disabled WikiNames
6 preserved line breaks
7
8 Restriction:
9 Line break preservation in tables are not supported.
10 You can still use <<BR>> in tables.
11
12 Tested with:
13 MoinMoin 1.9.7
14
15 Thanks to:
16 SixMen for NoCamelCase1.9
17 DavidMontgomery for nice tweaks
18 MoinMoin developpers and contributors
19
20 @copyright: 2014 by dossist.
21 @license: GNU GPL, see http://www.gnu.org/licenses/gpl for details.
22 """
23
24 import re
25 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
26
27 Dependencies = ['user']
28
29 def list_in_groupdict(keylist, groupdict):
30 """
31 checks if dictionary 'groupdict' has at least one key in list 'keylist'
32 """
33 for key in keylist:
34 if key in groupdict and groupdict[key] is not None:
35 return True
36 return False
37
38 class Parser(WikiParser):
39 # No line-break elements
40 # List of group labels defined in WikiParser.scan_rules (see original parser).
41 # Suppress <br> insertion to current line (nobreak_now) and to the next line (nobreak_next)
42 # when we find those elements in current line.
43 nobreak_now = ['li', 'li_none', 'ol', 'dl', 'table']
44 nobreak_next = ['heading', 'table']
45
46 def __init__(self, raw, request, **kw):
47 WikiParser.__init__(self, raw, request, **kw)
48 # state holders carried over lines
49 self.break_next = False # can <br> be inserted in the next line?
50 self.prev_list = False # were we in a list in the previous line?
51
52 def format(self, formatter):
53 """
54 same as original but resetting state holders at the end
55 """
56 WikiParser.format(self, formatter)
57 # reset those states every time format is done
58 self.break_next = False
59 self.prev_list = False
60
61 def scan(self, line, inhibit_p=False):
62 """
63 pass line to the original method, then modify the result.
64
65 * if we need <br> for the current line, we just indicate that the next line should begin with <br>,
66 and move on to the next line doing nothing to the current line.
67 * if the previous line needed <br>, we check whether current line is 'breakable',
68 and finally add <br> at the beginning of the output from original scan() method if conditions are met.
69 """
70 formatted_line = WikiParser.scan(self, line, inhibit_p=inhibit_p)
71
72 # match wiki patterns again to know what context we are in
73 match = self.scan_re.search(line)
74 if match:
75 match_dict = match.groupdict()
76 else:
77 match_dict = {}
78
79 # check if current line can be line-broken
80 break_now = not (list_in_groupdict(self.nobreak_now, match_dict) or # current line
81 self.in_table or self.in_pre or # no-linebreak states carried over lines
82 (self.prev_list is not self.in_list) or # need this when quitting from lists
83 self.line_was_empty) # finally we don't need line breaks for paragraph ends
84 # if conditions are met, append a br tag
85 if break_now and self.break_next:
86 formatted_line = self.formatter.linebreak(preformatted=0) + formatted_line
87 # in certain structures, we don't want line breaks in the next line
88 self.break_next = not (list_in_groupdict(self.nobreak_next, match_dict) or
89 self.in_table or self.in_pre)
90 # save current in_list status
91 self.prev_list = self.in_list
92
93 return formatted_line
94
95 def _word_repl(self, word, groups):
96 """
97 replace WikiName linking routine with nothingness
98 """
99 return self.formatter.nowikiword(word)
100 _word_bang_repl = _word_repl
101 _word_name_repl = _word_repl
102 _word_anchor_repl = _word_repl
添付ファイル
添付ファイルを参照するには、(下のファイル一覧にあるように)attachment:filenameと記述します。 [get]リンクのURLは変更される可能性が高いので、利用しないでください。ファイルを添付する権限がありません。