Description
Well that may be is more a feature but also it could be named problem or limitation.
Currently the highlight parser has precedence for parsing of any attachment before other parsers. If it is possible to highlight a mimetype it is hightlighted and not parsed by an other parser.
Example
if it can highlight rst markup it highlights it instead of rendering it
Inline ReST Testing
This is a test of using ReST attachments with MoinMoin. I really hope this works.
A | B |
C | D |
On my box it looks like:
Component selection
- general
Details
MoinMoin Version |
1.9 |
OS and Version |
|
Python Version |
|
Server Setup |
|
Server Details |
|
Language you are using the wiki in (set in the browser/UserPreferences) |
|
Workaround
Discussion
May be we should use a param for highlighting and try on default to call a specific parser if present. If there is no parser found it does fallback on highlighting. At the moment when pygments introduces the mimetype you have parsed on your own before then your files become highlighted. For some of these files it is also interesting to show the source highlighted. Currently we can't choose what we want.
On this wiki for example now every traceback.html attached to a bugreport is highlighted instead of rendered.
A simple 1.8 compatible solution is to add to each old highlight parser only the extenstions used by pygments lexer for this parser and to add all highlighting patterns to MIMETYPES_MORE. Also we have to force that the highlight parser is the first entry in parser_plugins.
1 diff -r ffaec355ee84 MoinMoin/parser/highlight.py
2 --- a/MoinMoin/parser/highlight.py Mon Dec 28 14:53:08 2009 +0000
3 +++ b/MoinMoin/parser/highlight.py Tue Jan 05 22:38:32 2010 +0100
4 @@ -28,6 +28,9 @@
5 if m and m.groups(0):
6 extensions.extend(m.groups(0))
7
8 +def extensions_from_lexer(parsername):
9 + lexer = pygments.lexers.get_lexer_by_name(parsername)
10 + extensions = [ext.strip('*') for ext in lexer.filenames if ext.startswith('*.')]
11
12 class PygmentsFormatter(pygments.formatter.Formatter):
13 """ a formatter for Pygments that uses the moin formatter for creating output """
14 @@ -169,4 +172,3 @@
15 fmt.result.append(formatter.code_area(0, self._code_id))
16 fmt.result.append(formatter.div(0))
17 self.request.write("".join(fmt.result))
18 -
19 diff -r ffaec355ee84 MoinMoin/parser/text_cplusplus.py
20 --- a/MoinMoin/parser/text_cplusplus.py Mon Dec 28 14:53:08 2009 +0000
21 +++ b/MoinMoin/parser/text_cplusplus.py Tue Jan 05 22:38:32 2010 +0100
22 @@ -19,8 +19,8 @@
23 """
24
25 from MoinMoin.parser.highlight import Parser as HighlightParser
26 -from MoinMoin.parser.highlight import Dependencies
27 +from MoinMoin.parser.highlight import extensions_from_lexer, Dependencies
28
29 class Parser(HighlightParser):
30 parsername = 'cpp' # Lexer name pygments recognizes
31 -
32 + extensions = extensions_from_lexer(parsername)
33 diff -r ffaec355ee84 MoinMoin/parser/text_diff.py
34 --- a/MoinMoin/parser/text_diff.py Mon Dec 28 14:53:08 2009 +0000
35 +++ b/MoinMoin/parser/text_diff.py Tue Jan 05 22:38:32 2010 +0100
36 @@ -19,8 +19,8 @@
37 """
38
39 from MoinMoin.parser.highlight import Parser as HighlightParser
40 -from MoinMoin.parser.highlight import Dependencies
41 +from MoinMoin.parser.highlight import extensions_from_lexer, Dependencies
42
43 class Parser(HighlightParser):
44 parsername = 'diff' # Lexer name pygments recognizes
45 -
46 + extensions = extensions_from_lexer(parsername)
47 diff -r ffaec355ee84 MoinMoin/parser/text_irssi.py
48 --- a/MoinMoin/parser/text_irssi.py Mon Dec 28 14:53:08 2009 +0000
49 +++ b/MoinMoin/parser/text_irssi.py Tue Jan 05 22:38:32 2010 +0100
50 @@ -19,8 +19,8 @@
51 """
52
53 from MoinMoin.parser.highlight import Parser as HighlightParser
54 -from MoinMoin.parser.highlight import Dependencies
55 +from MoinMoin.parser.highlight import extensions_from_lexer, Dependencies
56
57 class Parser(HighlightParser):
58 parsername = 'irc' # Lexer name pygments recognizes
59 -
60 + extensions = extensions_from_lexer(parsername)
61 diff -r ffaec355ee84 MoinMoin/parser/text_java.py
62 --- a/MoinMoin/parser/text_java.py Mon Dec 28 14:53:08 2009 +0000
63 +++ b/MoinMoin/parser/text_java.py Tue Jan 05 22:38:32 2010 +0100
64 @@ -19,8 +19,8 @@
65 """
66
67 from MoinMoin.parser.highlight import Parser as HighlightParser
68 -from MoinMoin.parser.highlight import Dependencies
69 +from MoinMoin.parser.highlight import extensions_from_lexer, Dependencies
70
71 class Parser(HighlightParser):
72 parsername = 'java' # Lexer name pygments recognizes
73 -
74 + extensions = extensions_from_lexer(parsername)
75 diff -r ffaec355ee84 MoinMoin/parser/text_pascal.py
76 --- a/MoinMoin/parser/text_pascal.py Mon Dec 28 14:53:08 2009 +0000
77 +++ b/MoinMoin/parser/text_pascal.py Tue Jan 05 22:38:32 2010 +0100
78 @@ -19,8 +19,10 @@
79 """
80
81 from MoinMoin.parser.highlight import Parser as HighlightParser
82 -from MoinMoin.parser.highlight import Dependencies
83 +from MoinMoin.parser.highlight import extensions_from_lexer, Dependencies
84
85 class Parser(HighlightParser):
86 parsername = 'pascal' # Lexer name pygments recognizes
87 + extensions = extensions_from_lexer(parsername)
88
89 +
90 diff -r ffaec355ee84 MoinMoin/parser/text_python.py
91 --- a/MoinMoin/parser/text_python.py Mon Dec 28 14:53:08 2009 +0000
92 +++ b/MoinMoin/parser/text_python.py Tue Jan 05 22:38:32 2010 +0100
93 @@ -19,8 +19,9 @@
94 """
95
96 from MoinMoin.parser.highlight import Parser as HighlightParser
97 -from MoinMoin.parser.highlight import Dependencies
98 +from MoinMoin.parser.highlight import extensions_from_lexer, Dependencies
99
100 class Parser(HighlightParser):
101 parsername = 'python' # Lexer name pygments recognizes
102 + extensions = extensions_from_lexer(parsername)
103
104 diff -r ffaec355ee84 MoinMoin/wikiutil.py
105 --- a/MoinMoin/wikiutil.py Mon Dec 28 14:53:08 2009 +0000
106 +++ b/MoinMoin/wikiutil.py Tue Jan 05 22:38:32 2010 +0100
107 @@ -839,7 +839,7 @@
108 ### mimetype support
109 #############################################################################
110 import mimetypes
111 -
112 +import pygments.lexers
113 MIMETYPES_MORE = {
114 # OpenOffice 2.x & other open document stuff
115 '.odt': 'application/vnd.oasis.opendocument.text',
116 @@ -868,6 +868,13 @@
117 '.wmv': 'video/x-ms-wmv',
118 '.swf': 'application/x-shockwave-flash',
119 }
120 +# add all mimetype patterns of pygments
121 +for name, short, patterns, mime in pygments.lexers.get_all_lexers():
122 + for pattern in list(patterns):
123 + if pattern.startswith('*.') and mime:
124 + patt = pattern.strip('*')
125 + MIMETYPES_MORE[patt] = mime[0]
126 +
127 [mimetypes.add_type(mimetype, ext, True) for ext, mimetype in MIMETYPES_MORE.items()]
128
129 MIMETYPES_sanitize_mapping = {
130 @@ -1188,7 +1195,13 @@
131 """
132 if not hasattr(cfg.cache, 'EXT_TO_PARSER'):
133 etp, etd = {}, None
134 - for pname in getPlugins('parser', cfg):
135 + parser_plugins = getPlugins('parser', cfg)
136 + # force highlight parser first entry in the list
137 + # this makes it possible to overwrite an extension
138 + # for a different parser
139 + parser_plugins.remove('highlight')
140 + parser_plugins = ['highlight'] + parser_plugins
141 + for pname in parser_plugins:
142 try:
143 Parser = importPlugin(cfg, 'parser', pname, 'Parser')
144 except PluginMissingError:
Plan
- Priority:
- Assigned to:
- Status:
fixed by http://hg.moinmo.in/moin/1.9/rev/b7ab238032dd (based on the patch shown above), please test
extensions for rst parser: http://hg.moinmo.in/moin/1.9/rev/0c424b6dc029
- shall we define extensions for creole / moin wiki?
- I wanted to use moin attachments in the past and I remember at least one other on #moin asking for that.