changeset 2600:d62370bd12e1

fix #182 creole interwiki links; creole table headings; enhance creole horizontal rule
author RogerHaase <haaserd@gmail.com>
date Mon, 19 May 2014 09:54:26 -0700
parents 636f439f2bbf
children ff371330b4ec
files MoinMoin/converter/_tests/test_creole_in.py MoinMoin/converter/creole_in.py MoinMoin/themes/basic/static/css/basic.css MoinMoin/themes/basic/static/custom-less/basic.less MoinMoin/themes/foobar/static/css/common.css MoinMoin/themes/foobar/static/css/stylus/main.styl MoinMoin/themes/modernized/static/css/common.css MoinMoin/themes/modernized/static/css/stylus/main.styl
diffstat 8 files changed, 77 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/_tests/test_creole_in.py	Sun May 11 13:39:38 2014 -0700
+++ b/MoinMoin/converter/_tests/test_creole_in.py	Mon May 19 09:54:26 2014 -0700
@@ -8,7 +8,7 @@
 
 import re
 
-from MoinMoin.util.tree import moin_page, xlink, html
+from MoinMoin.util.tree import moin_page, xlink, html, xinclude
 
 from ..creole_in import Converter
 
@@ -17,7 +17,8 @@
     namespaces = {
         moin_page: '',
         xlink: 'xlink',
-        html: 'xhtml'
+        html: 'xhtml',
+        xinclude: 'xinclude',
     }
 
     output_re = re.compile(r'\s+xmlns(:\S+)?="[^"]+"')
@@ -41,6 +42,8 @@
                 '<page><body><p><a xlink:href="http://moinmo.in/">http://moinmo.in/</a></p></body></page>'),
             (u'[[http://moinmo.in/]]',
                 '<page><body><p><a xlink:href="http://moinmo.in/">http://moinmo.in/</a></p></body></page>'),
+            (u'[[MoinMoin:InterWiki]]',
+                '<page><body><p><a xlink:href="wiki://MoinMoin/InterWiki">InterWiki</a></p></body></page>'),
             (u'[[javascript:alert("xss")]]',
                 '<page><body><p><a xlink:href="wiki.local:javascript:alert%28%22xss%22%29">javascript:alert("xss")</a></p></body></page>'),
             (u'[[http://moinmo.in/|MoinMoin]]',
@@ -51,8 +54,10 @@
                 '<page><body><p><object xlink:href="http://moinmo.in/" /></p></body></page>'),
             (u'{{http://moinmo.in/|MoinMoin}}',
                 '<page><body><p><object xhtml:alt="MoinMoin" xlink:href="http://moinmo.in/" /></p></body></page>'),
+            (u'{{my.png}}',
+                '<page><body><p><xinclude:include xinclude:href="wiki.local:my.png" /></p></body></page>'),
             (u'----',
-                '<page><body><separator /></body></page>'),
+                '<page><body><separator class="moin-hr3" /></body></page>'),
         ]
         for i in data:
             yield (self.do, ) + i
--- a/MoinMoin/converter/creole_in.py	Sun May 11 13:39:38 2014 -0700
+++ b/MoinMoin/converter/creole_in.py	Mon May 19 09:54:26 2014 -0700
@@ -30,6 +30,7 @@
 from MoinMoin.constants.misc import URI_SCHEMES
 from MoinMoin.util.iri import Iri
 from MoinMoin.util.tree import moin_page, xlink, xinclude, html
+from MoinMoin.util.interwiki import is_known_wiki
 
 from ._args_wiki import parse as parse_arguments
 from ._wiki_macro import ConverterMacro
@@ -222,9 +223,9 @@
 
     block_separator = r'(?P<separator> ^ \s* ---- \s* $ )'
 
-    def block_separator_repl(self, _iter_content, stack, separator):
+    def block_separator_repl(self, _iter_content, stack, separator, hr_class=u'moin-hr3'):
         stack.clear()
-        stack.top_append(moin_page.separator())
+        stack.top_append(moin_page.separator(attrib={moin_page.class_: hr_class}))
 
     block_table = r"""
         (?P<table>
@@ -305,7 +306,6 @@
     def inline_escape_repl(self, stack, escape, escaped_char):
         stack.top_append(escaped_char)
 
-    # TODO: Parse interwiki the same way as Moin Wiki.
     inline_link = r"""
         (?P<link>
             \[\[
@@ -317,7 +317,13 @@
                     [^|]+?
                 )
                 |
-                (?P<link_page> [^|]+? )
+                (
+                    (?P<link_interwiki_site>[A-Z][a-zA-Z]+)
+                    :
+                    (?P<link_interwiki_item>[^|]+) # accept any item name; will verify link_interwiki_site below
+                )
+                |
+                (?P<link_item> [^|]+? )
             )
             \s*
             ([|] \s* (?P<link_text>.+?) \s*)?
@@ -325,21 +331,40 @@
         )
     """
 
-    def inline_link_repl(self, stack, link, link_url=None, link_page=None, link_text=None):
+    def inline_link_repl(self, stack, link, link_url=None, link_item=None, link_text=None,
+                         link_interwiki_site=None, link_interwiki_item=None):
         """Handle all kinds of links."""
-
-        if link_page is not None:
+        if link_interwiki_site:
+            if is_known_wiki(link_interwiki_site):
+                link = Iri(scheme='wiki',
+                           authority=link_interwiki_site,
+                           path='/' + link_interwiki_item)
+                element = moin_page.a(attrib={xlink.href: link})
+                stack.push(element)
+                if link_text:
+                    self.parse_inline(link_text, stack, self.inlinedesc_re)
+                else:
+                    stack.top_append(link_interwiki_item)
+                stack.pop()
+                return
+            else:
+                # assume local language uses ":" inside of words, set link_item and continue
+                link_item = '{0}:{1}'.format(link_interwiki_site, link_interwiki_item)
+        if link_item is not None:
             att = 'attachment:'  # moin 1.9 needed this for an attached file
-            if link_page.startswith(att):
-                link_page = '/' + link_page[len(att):]  # now we have a subitem
-            target = unicode(Iri(scheme='wiki.local', path=link_page))
-            text = link_page
+            if link_item.startswith(att):
+                link_item = '/' + link_item[len(att):]  # now we have a subitem
+            target = unicode(Iri(scheme='wiki.local', path=link_item))
+            text = link_item
         else:
             target = link_url
             text = link_url
         element = moin_page.a(attrib={xlink.href: target})
         stack.push(element)
-        self.parse_inline(link_text or text, stack, self.link_desc_re)
+        if link_text:
+            self.parse_inline(link_text, stack, self.inlinedesc_re)
+        else:
+            stack.top_append(text)
         stack.pop()
 
     inline_macro = r"""
@@ -528,12 +553,17 @@
     """
 
     def tablerow_cell_repl(self, stack, cell, cell_text, cell_head=None):
-        element = moin_page.table_cell()
-        stack.push(element)
+        """
+        Creole has feature that allows table headings to be either row based or column based.
 
-        # TODO: support table headings
+        We avoid use of HTML5 row based thead tag and apply CSS styling to any cell marked as a heading.
+        """
+        attrib = {}
+        if cell_head:
+            attrib[moin_page.class_] = 'moin-thead'
+        element = moin_page.table_cell(attrib=attrib)
+        stack.push(element)
         self.parse_inline(cell_text, stack)
-
         stack.pop_name('table-cell')
 
     # Block elements
@@ -563,6 +593,15 @@
     )
     inline_re = re.compile('|'.join(inline), re.X | re.U)
 
+    inlinedesc = (
+        inline_macro,
+        inline_nowiki,
+        inline_emph,
+        inline_strong,
+        inline_object,
+    )
+    inlinedesc_re = re.compile('|'.join(inlinedesc), re.X | re.U)
+
     # Link description
     link_desc = (
         inline_object,
--- a/MoinMoin/themes/basic/static/css/basic.css	Sun May 11 13:39:38 2014 -0700
+++ b/MoinMoin/themes/basic/static/css/basic.css	Mon May 19 09:54:26 2014 -0700
@@ -6323,3 +6323,6 @@
 ul.moin-breadcrumb li:hover ul.moin-bcs-subitems {
   display: block;
 }
+.moin-thead {
+  background-color: silver;
+}
--- a/MoinMoin/themes/basic/static/custom-less/basic.less	Sun May 11 13:39:38 2014 -0700
+++ b/MoinMoin/themes/basic/static/custom-less/basic.less	Mon May 19 09:54:26 2014 -0700
@@ -296,3 +296,6 @@
 ul.moin-breadcrumb li:hover ul.moin-bcs-subitems{
   display: block;
 }
+.moin-thead{
+    background-color: silver;
+}
--- a/MoinMoin/themes/foobar/static/css/common.css	Sun May 11 13:39:38 2014 -0700
+++ b/MoinMoin/themes/foobar/static/css/common.css	Mon May 19 09:54:26 2014 -0700
@@ -405,6 +405,7 @@
 table th,table td{padding:.3em .4em;vertical-align:middle;text-align:left}
 table th{border:1px solid #ccc;background-color:#808080;color:#fff}
 table td{border:1px solid #ccc}
+.moin-thead{background-color:#808080}
 table.zebra{border:1px solid #ccc;border-collapse:separate;border-spacing:1px;width:98%;border-radius:6px;}
 table.zebra thead{background-color:#808080;color:#fff}
 table.zebra tfoot{background-color:#d6d5d0}
--- a/MoinMoin/themes/foobar/static/css/stylus/main.styl	Sun May 11 13:39:38 2014 -0700
+++ b/MoinMoin/themes/foobar/static/css/stylus/main.styl	Mon May 19 09:54:26 2014 -0700
@@ -947,6 +947,9 @@
     td
         border border_style
 
+.moin-thead
+    background-color table_header_color
+
 table.zebra
     border border_style
     border-collapse separate
--- a/MoinMoin/themes/modernized/static/css/common.css	Sun May 11 13:39:38 2014 -0700
+++ b/MoinMoin/themes/modernized/static/css/common.css	Mon May 19 09:54:26 2014 -0700
@@ -245,6 +245,7 @@
 th{border:1px solid #4e7da9;background-color:#708090;text-align:center;color:#d8dfe9}
 td{border:1px solid #4e7da9}
 td p{margin:0;padding:0}
+.moin-thead{background-color:#708090}
 table.zebra{border-collapse:separate;border-spacing:1px;width:98%;border:1px solid #4e7da9;border-radius:6px}
 .zebra thead{background-color:#708090}
 .zebra tfoot{background-color:#dfdfdf}
--- a/MoinMoin/themes/modernized/static/css/stylus/main.styl	Sun May 11 13:39:38 2014 -0700
+++ b/MoinMoin/themes/modernized/static/css/stylus/main.styl	Mon May 19 09:54:26 2014 -0700
@@ -239,6 +239,9 @@
     margin 0
     padding 0
 
+.moin-thead
+    background-color header_bg_color
+
 table.zebra
     border-collapse separate
     border-spacing 1px