changeset 5284:a83a65fcbb69

bug fix for MoinMoinBugs/LineNumbersWorkingBuggyWithHighlightParser (thanks to Eugene Syromyatnikov for the patch)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 15 Nov 2009 22:50:47 +0100
parents f68e18305d05
children be3d5338f0a3
files MoinMoin/formatter/dom_xml.py MoinMoin/formatter/text_docbook.py MoinMoin/formatter/text_html.py MoinMoin/formatter/text_plain.py MoinMoin/formatter/text_python.py MoinMoin/formatter/text_xml.py MoinMoin/parser/highlight.py MoinMoin/web/static/htdocs/classic/css/common.css MoinMoin/web/static/htdocs/modern/css/common.css MoinMoin/web/static/htdocs/modernized/css/common.css MoinMoin/web/static/htdocs/rightsidebar/css/common.css
diffstat 11 files changed, 70 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/dom_xml.py	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/formatter/dom_xml.py	Sun Nov 15 22:50:47 2009 +0100
@@ -372,7 +372,7 @@
     def big(self, on, **kw):
         return self._set_tag('big', on)
 
-    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1):
+    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1, msg=None):
         kw = {'id': code_id,
               'type': code_type,
               'show': show,
--- a/MoinMoin/formatter/text_docbook.py	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/formatter/text_docbook.py	Sun Nov 15 22:50:47 2009 +0100
@@ -497,7 +497,7 @@
 
 ### Code area #######################################################
 
-    def code_area(self, on, code_id, code_type=None, show=0, start=-1, step=-1):
+    def code_area(self, on, code_id, code_type=None, show=0, start=-1, step=-1, msg=None):
         """Creates a formatted code region using screen or programlisting,
         depending on if a programming language was defined (code_type).
 
--- a/MoinMoin/formatter/text_html.py	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/formatter/text_html.py	Sun Nov 15 22:50:47 2009 +0100
@@ -859,7 +859,7 @@
 </script>
 """
 
-    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1):
+    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1, msg=None):
         """Creates a formatted code region, with line numbering.
 
         This region is formatted as a <div> with a <pre> inside it.  The
@@ -885,6 +885,12 @@
             # id in here no longer used
             self._code_area_state = [None, show, start, step, start]
 
+            if msg:
+                attr = {'class': 'codemsg'}
+                res.append(self._open('div', attr={'class': 'codemsg'}))
+                res.append(self.text(msg))
+                res.append(self._close('div'))
+
             # Open the code div - using left to right always!
             attr = {'class': 'codearea', 'lang': 'en', 'dir': 'ltr'}
             res.append(self._open('div', attr=attr))
--- a/MoinMoin/formatter/text_plain.py	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/formatter/text_plain.py	Sun Nov 15 22:50:47 2009 +0100
@@ -170,7 +170,7 @@
     def big(self, on, **kw):
         return u''
 
-    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1):
+    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1, msg=None):
         snip = u'---CodeArea'
         snip = snip + (u'-' * (78 - len(snip)))
         if on:
--- a/MoinMoin/formatter/text_python.py	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/formatter/text_python.py	Sun Nov 15 22:50:47 2009 +0100
@@ -235,7 +235,7 @@
         else:
             return self.formatter.line_anchorlink(on, lineno)
 
-    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1):
+    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1, msg=None):
         if on:
             # update state of the HTML formatter
             self.formatter._in_code_area = 1
--- a/MoinMoin/formatter/text_xml.py	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/formatter/text_xml.py	Sun Nov 15 22:50:47 2009 +0100
@@ -221,7 +221,7 @@
         # TODO, see text_html formatter
         return ''
 
-    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1):
+    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1, msg=None):
         return ('<codearea id="%s">' % code_id, '</codearea')[not on]
 
     def code_line(self, on):
--- a/MoinMoin/parser/highlight.py	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/parser/highlight.py	Sun Nov 15 22:50:47 2009 +0100
@@ -116,13 +116,14 @@
         self.request = request
         self.raw = raw.strip('\n')
         self.filename = filename
+
         if self.parsername == 'highlight':
             # user is directly using the highlight parser
             parts = format_args.split(None)
             if parts:
                 self.syntax = parts[0]
             else:
-                self.syntax = ''
+                self.syntax = 'text'
             if len(parts) > 1:
                 params = ' '.join(parts[1:])
             else:
@@ -134,10 +135,11 @@
         self.show_nums, self.num_start, self.num_step, attrs = parse_start_step(request, params)
 
     def format(self, formatter):
+        _ = self.request.getText
         fmt = PygmentsFormatter(formatter)
         fmt.result.append(formatter.div(1, css_class="highlight %s" % self.syntax))
         self._code_id = hash_new('sha1', self.raw.encode(config.charset)).hexdigest()
-        fmt.result.append(formatter.code_area(1, self._code_id, self.parsername, self.show_nums, self.num_start, self.num_step))
+        msg = None
         if self.filename is not None:
             try:
                 lexer = pygments.lexers.get_lexer_for_filename(self.filename)
@@ -148,8 +150,9 @@
             try:
                 lexer = pygments.lexers.get_lexer_by_name(self.syntax)
             except pygments.util.ClassNotFound:
-                fmt.result.append(formatter.text('#!%s\n' % self.syntax))
+                msg = _("Lexer \"%s\" not found. Rendering as plain text.") % self.syntax
                 lexer = pygments.lexers.TextLexer()
+        fmt.result.append(formatter.code_area(1, self._code_id, self.parsername, self.show_nums, self.num_start, self.num_step, msg))
         pygments.highlight(self.raw, lexer, fmt)
         fmt.result.append(formatter.code_area(0, self._code_id))
         fmt.result.append(formatter.div(0))
--- a/MoinMoin/web/static/htdocs/classic/css/common.css	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/web/static/htdocs/classic/css/common.css	Sun Nov 15 22:50:47 2009 +0100
@@ -265,6 +265,19 @@
 
 /* CSS for new code_area markup used by Colorizer and ParserBase */
 
+div.codemsg {
+       margin: 0.5em 0;
+       padding: 0.5em;
+       padding-left:2.5em;
+       background:none;
+       border: 1pt solid #CCBDAE;
+       background-color: #F7F0E0;
+       background-image:url('../img/alert.png');
+       background-repeat:no-repeat;
+       background-position: 0.5em 0.5em;
+       color: black;
+}
+
 div.codearea { /* the div makes the border */
 	margin: 0.5em 0;
 	padding: 0;
--- a/MoinMoin/web/static/htdocs/modern/css/common.css	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/web/static/htdocs/modern/css/common.css	Sun Nov 15 22:50:47 2009 +0100
@@ -294,6 +294,19 @@
 
 /* CSS for new code_area markup used by Colorizer and ParserBase */
 
+div.codemsg {
+       margin: 0.5em 0;
+       padding: 0.5em;
+       padding-left:2.5em;
+       background:none;
+       border: 1pt solid #CCBDAE;
+       background-color: #F7F0E0;
+       background-image:url('../img/alert.png');
+       background-repeat:no-repeat;
+       background-position: 0.5em 0.5em;
+       color: black;
+}
+
 div.codearea { /* the div makes the border */
 	margin: 0.5em 0;
 	padding: 0;
--- a/MoinMoin/web/static/htdocs/modernized/css/common.css	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/web/static/htdocs/modernized/css/common.css	Sun Nov 15 22:50:47 2009 +0100
@@ -305,6 +305,19 @@
 
 /* CSS for new code_area markup used by Colorizer and ParserBase */
 
+div.codemsg {
+       margin: 0.5em 0;
+       padding: 0.5em;
+       padding-left:2.5em;
+       background:none;
+       border: 1pt solid #CCBDAE;
+       background-color: #F7F0E0;
+       background-image:url('../img/alert.png');
+       background-repeat:no-repeat;
+       background-position: 0.5em 0.5em;
+       color: black;
+}
+
 div.codearea { /* the div makes the border */
 	margin: 0.5em 0;
 	padding: 0;
--- a/MoinMoin/web/static/htdocs/rightsidebar/css/common.css	Sun Nov 15 21:54:56 2009 +0100
+++ b/MoinMoin/web/static/htdocs/rightsidebar/css/common.css	Sun Nov 15 22:50:47 2009 +0100
@@ -286,6 +286,19 @@
 
 /* CSS for new code_area markup used by Colorizer and ParserBase */
 
+div.codemsg {
+       margin: 0.5em 0;
+       padding: 0.5em;
+       padding-left:2.5em;
+       background:none;
+       border: 1pt solid #CCBDAE;
+       background-color: #F7F0E0;
+       background-image:url('../img/alert.png');
+       background-repeat:no-repeat;
+       background-position: 0.5em 0.5em;
+       color: black;
+}
+
 div.codearea { /* the div makes the border */
 	margin: 0.5em 0;
 	padding: 0;