Commits

Roger Haase committed 611d8ab

fix broken admonitions in ReST, Docbook; add 4 missing admonition types; do not suppress ReST syntax error messages

Comments (0)

Files changed (8)

MoinMoin/converter/_tests/test_rst_in.py

             (u'1. a\n   b\n   c\n\n2. b\n\n   d', '''<page><body><list item-label-generate="ordered"><list-item><list-item-body><p>a
 b
 c</p></list-item-body></list-item><list-item><list-item-body><p>b</p><p>d</p></list-item-body></list-item></list></body></page>'''),
-            (u'1. a\n2. b\n\nA. c\n\na. A\n\n   3. B\n\n   4. C\n\n', '<page><body><list item-label-generate="ordered"><list-item><list-item-body><p>a</p></list-item-body></list-item><list-item><list-item-body><p>b</p></list-item-body></list-item></list><list item-label-generate="ordered" list-style-type="upper-alpha"><list-item><list-item-body><p>c</p></list-item-body></list-item></list><list item-label-generate="ordered" list-style-type="lower-alpha"><list-item><list-item-body><p>A</p><list item-label-generate="ordered"><list-item><list-item-body><p>B</p></list-item-body></list-item><list-item><list-item-body><p>C</p></list-item-body></list-item></list></list-item-body></list-item></list></body></page>'),
+            (u'1. a\n2. b\n\nA. c\n\na. A\n\n   1. B\n\n   2. C\n\n', '<page><body><list item-label-generate="ordered"><list-item><list-item-body><p>a</p></list-item-body></list-item><list-item><list-item-body><p>b</p></list-item-body></list-item></list><list item-label-generate="ordered" list-style-type="upper-alpha"><list-item><list-item-body><p>c</p></list-item-body></list-item></list><list item-label-generate="ordered" list-style-type="lower-alpha"><list-item><list-item-body><p>A</p><list item-label-generate="ordered"><list-item><list-item-body><p>B</p></list-item-body></list-item><list-item><list-item-body><p>C</p></list-item-body></list-item></list></list-item-body></list-item></list></body></page>'),
             (u'* A\n\n   - B\n\n      + C\n\n   - D\n\n* E', '<page><body><list item-label-generate="unordered"><list-item><list-item-body><p>A</p><list><list-item><list-item-body><list item-label-generate="unordered"><list-item><list-item-body><p>B</p><list><list-item><list-item-body><list item-label-generate="unordered"><list-item><list-item-body><p>C</p></list-item-body></list-item></list></list-item-body></list-item></list></list-item-body></list-item><list-item><list-item-body><p>D</p></list-item-body></list-item></list></list-item-body></list-item></list></list-item-body></list-item><list-item><list-item-body><p>E</p></list-item-body></list-item></list></body></page>'),
-            (u'what\n      def\n\nhow\n      to', '<page><body><list><list-item><list-item-label>what</list-item-label><list-item-body><p>def</p></list-item-body></list-item><list-item><list-item-label>how</list-item-label><list-item-body><p>to</p></list-item-body></list-item></list></body></page>')
+            (u'what\n      def\n\nhow\n      to', '<page><body><list><list-item><list-item-label>what</list-item-label><list-item-body><p>def</p></list-item-body></list-item><list-item><list-item-label>how</list-item-label><list-item-body><p>to</p></list-item-body></list-item></list></body></page>'),
+            # starting an ordered list with a value other than 1 generates an error
+            (u' 3. A\n #. B',
+                '<page><body><list><list-item><list-item-body><list item-label-generate="ordered"><list-item><list-item-body><p>A</p>'
+                '</list-item-body></list-item><list-item><list-item-body><p>B</p></list-item-body></list-item></list>'
+                '<admonition type="error"><p>Enumerated list start value not ordinal-1: "3" (ordinal 3)</p></admonition>'
+                '</list-item-body></list-item></list></body></page>'),
         ]
         for i in data:
             yield (self.do, ) + i

MoinMoin/converter/docbook_in.py

     # DocBook has admonition as individual element, but the DOM Tree
     # has only one element for it, so we will convert all the DocBook
     # admonitions in this list, into the admonition element of the DOM Tree.
-    admonition_tags = set(['caution', 'important', 'note', 'tip', 'warning'])
+    admonition_tags = set(['attention', 'caution', 'danger', 'error', 'hint', 'important', 'note', 'tip', 'warning'])
 
     # DocBook can handle three kind of media: audio, image, video. Here
     # is an helper dictionary to process such of element.

MoinMoin/converter/html_out.py

         return self.new_copy(_tag_html_a, elem, attrib)
 
     def visit_moinpage_admonition(self, elem):
+        """Used by ReST and docbook."""
         attrib = {}
-        key = html('class')
-        # XXX need to add some keyword to protect the class
-        attrib[key] = elem.get(moin_page.type)
+        valid_classes = set(["attention", "caution", "danger", "error", "hint", "important", "note", "tip", "warning"])
+        cls = elem.get(moin_page.type)
+        if cls in valid_classes:
+            attrib[html.class_] = cls
+        elem.attrib = {}
         return self.new_copy(html.div, elem, attrib)
 
     def visit_moinpage_blockcode(self, elem):

MoinMoin/converter/rst_in.py

         pass
 
     def visit_admonition(self, node):
+        # we do not support generic admonitions per http://docutils.sourceforge.net/docs/ref/rst/directives.html#generic-admonition
         self.open_moin_page_node(moin_page.admonition())
 
     def depart_admonition(self, node=None):
         self.close_moin_page_node()
 
-    visit_note = visit_admonition
-    visit_important = visit_admonition
-    visit_danger = visit_admonition
-    visit_caution = visit_admonition
-    visit_attention = visit_admonition
-    visit_tip = visit_admonition
-    visit_warning = visit_admonition
+    # see http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions
+    def visit_attention(self, node):
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'attention'}))
+
+    depart_attention = depart_admonition
+
+    def visit_caution(self, node):
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'caution'}))
+
+    depart_caution = depart_admonition
+
+    def visit_danger(self, node):
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'danger'}))
+
+    depart_danger = depart_admonition
+
+    def visit_error(self, node):
+        # this is used to process parsing errors as well as user error admonitions
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'error'}))
+
+    depart_error = depart_admonition
+
+    def visit_hint(self, node):
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'hint'}))
+
+    depart_hint = depart_admonition
+
+    def visit_important(self, node):
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'important'}))
+
+    depart_important = depart_admonition
+
+    def visit_note(self, node):
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'note'}))
 
     depart_note = depart_admonition
-    depart_important = depart_admonition
-    depart_danger = depart_admonition
-    depart_caution = depart_admonition
-    depart_attention = depart_admonition
+
+    def visit_tip(self, node):
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'tip'}))
+
     depart_tip = depart_admonition
+
+    def visit_warning(self, node):
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'warning'}))
+
     depart_warning = depart_admonition
 
-    def visit_error(self, node):
-        self.open_moin_page_node(moin_page.error())
-
-    def depart_error(self, node=None):
-        self.close_moin_page_node()
-
     def visit_block_quote(self, node):
         self.open_moin_page_node(moin_page.list())
         self.open_moin_page_node(moin_page.list_item())
         self.close_moin_page_node()
 
     def visit_system_message(self, node):
-        node.children = []
+        # we have encountered a parsing error, insert an error message
+        self.open_moin_page_node(moin_page.admonition({moin_page.type: 'error'}))
 
     def depart_system_message(self, node):
-        pass
+        self.close_moin_page_node()
 
     def visit_table(self, node):
         self.open_moin_page_node(moin_page.table())
                                   '\n'
                                   '  {1}\n'
                                   '\n'
-                                  '  Go back and try fix that.\n'
+                                  '  Go back and try to fix that.\n'
                                   '\n').format(str_num, string_numb.group(2).replace('\n', '\n  '))]
                         continue
                 else:

MoinMoin/themes/foobar/static/css/common.css

 .moin-thumbs-up:before { content: url('../img/smileys/thumbs-up.png'); }
 .moin-tired:before { content: url('../img/smileys/tired.png'); }
 .moin-tongue:before { content: url('../img/smileys/tongue.png'); }
+#moin-content div.attention{background-image:url("../img/admonitions/important.png")}
 #moin-content div.caution{background-image:url("../img/admonitions/caution.png")}
+#moin-content div.danger{background-image:url("../img/admonitions/warning.png")}
+#moin-content div.error{background-image:url("../img/admonitions/warning.png")}
+#moin-content div.hint{background-image:url("../img/admonitions/tip.png")}
 #moin-content div.important{background-image:url("../img/admonitions/important.png")}
 #moin-content div.note{background-image:url("../img/admonitions/note.png")}
 #moin-content div.tip{background-image:url("../img/admonitions/tip.png")}
 #moin-content div.warning{background-image:url("../img/admonitions/warning.png")}
-#moin-content div.caution,#moin-content div.important,#moin-content div.note,#moin-content div.tip,#moin-content div.warning{color:#000;background-color:#f9f9ff;background-repeat:no-repeat;background-position:8px 8px;border:1px solid #e5e5e5;margin:10px 30px 10px 30px;min-height:64px;padding-left:64px;clear:both;}
-#moin-content div.caution p,#moin-content div.important p,#moin-content div.note p,#moin-content div.tip p,#moin-content div.warning p{margin-top:8px}
+#moin-content div.attention,#moin-content div.caution,#moin-content div.danger,#moin-content div.error,#moin-content div.hint,#moin-content div.important,#moin-content div.note,#moin-content div.tip,#moin-content div.warning{color:#000;background-color:#f9f9ff;background-repeat:no-repeat;background-position:8px 8px;border:1px solid #e5e5e5;margin:10px 30px 10px 30px;min-height:64px;padding-left:64px;clear:both;}
+#moin-content div.attention p,#moin-content div.caution p,#moin-content div.danger p,#moin-content div.error p,#moin-content div.hint p,#moin-content div.important p,#moin-content div.note p,#moin-content div.tip p,#moin-content div.warning p{margin-top:8px}
 /* wiki parser  - no moin- prefix added here, these classes are used within pages: {{{#!wiki solid  */
 .comment { color: #555; background-color: #DDF; }
 .red { background-color: #FCC; }

MoinMoin/themes/foobar/static/css/stylus/admonitions.styl

-// admonitions  - no moin- prefix added  here, these classes are used within pages: {{{#!wiki caution
+// admonitions  - no moin- prefix added  here, these classes are used within moinwiki: {{{#!wiki caution
+// ReST: .. caution:: some text
+// Docbook: <caution><para>some text</para></caution>
 
+// TODO: create icons for attention, danger, error, and hint.
 #moin-content
+    div.attention
+        background-image url("../img/admonitions/important.png")
     div.caution
         background-image url("../img/admonitions/caution.png")
+    div.danger
+        background-image url("../img/admonitions/warning.png")
+    div.error
+        background-image url("../img/admonitions/warning.png")
+    div.hint
+        background-image url("../img/admonitions/tip.png")
     div.important
         background-image url("../img/admonitions/important.png")
     div.note
     div.warning
         background-image url("../img/admonitions/warning.png")
 
-    div.caution, div.important, div.note, div.tip, div.warning
+    div.attention, div.caution, div.danger, div.error, div.hint, div.important, div.note, div.tip, div.warning
         color black
         background-color #F9F9FF
         background-repeat no-repeat

MoinMoin/themes/modernized/static/css/common.css

 .moin-thumbs-up:before { content: url('../img/smileys/thumbs-up.png'); }
 .moin-tired:before { content: url('../img/smileys/tired.png'); }
 .moin-tongue:before { content: url('../img/smileys/tongue.png'); }
+#moin-content div.attention{background-image:url("../img/admonitions/important.png")}
 #moin-content div.caution{background-image:url("../img/admonitions/caution.png")}
+#moin-content div.danger{background-image:url("../img/admonitions/warning.png")}
+#moin-content div.error{background-image:url("../img/admonitions/warning.png")}
+#moin-content div.hint{background-image:url("../img/admonitions/tip.png")}
 #moin-content div.important{background-image:url("../img/admonitions/important.png")}
 #moin-content div.note{background-image:url("../img/admonitions/note.png")}
 #moin-content div.tip{background-image:url("../img/admonitions/tip.png")}
 #moin-content div.warning{background-image:url("../img/admonitions/warning.png")}
-#moin-content div.caution,#moin-content div.important,#moin-content div.note,#moin-content div.tip,#moin-content div.warning{color:#000;background-color:#f9f9ff;background-repeat:no-repeat;background-position:8px 8px;border:1px solid #e5e5e5;margin:10px 30px 10px 30px;min-height:64px;padding-left:64px;clear:both;}
-#moin-content div.caution p,#moin-content div.important p,#moin-content div.note p,#moin-content div.tip p,#moin-content div.warning p{margin-top:8px}
+#moin-content div.attention,#moin-content div.caution,#moin-content div.danger,#moin-content div.error,#moin-content div.hint,#moin-content div.important,#moin-content div.note,#moin-content div.tip,#moin-content div.warning{color:#000;background-color:#f9f9ff;background-repeat:no-repeat;background-position:8px 8px;border:1px solid #e5e5e5;margin:10px 30px 10px 30px;min-height:64px;padding-left:64px;clear:both;}
+#moin-content div.attention p,#moin-content div.caution p,#moin-content div.danger p,#moin-content div.error p,#moin-content div.hint p,#moin-content div.important p,#moin-content div.note p,#moin-content div.tip p,#moin-content div.warning p{margin-top:8px}
 /* wiki parser  - no moin- prefix added here, these classes are used within pages: {{{#!wiki solid  */
 .comment { color: #555; background-color: #DDF; }
 .red { background-color: #FCC; }

MoinMoin/themes/modernized/static/css/stylus/admonitions.styl

-// admonitions  - no moin- prefix added  here, these classes are used within pages: {{{#!wiki caution
+// admonitions  - no moin- prefix added  here, these classes are used within moinwiki: {{{#!wiki caution
+// ReST: .. caution:: some text
+// Docbook: <caution><para>some text</para></caution>
 
+// TODO: create icons for attention, danger, error, and hint.
 #moin-content
+    div.attention
+        background-image url("../img/admonitions/important.png")
     div.caution
         background-image url("../img/admonitions/caution.png")
+    div.danger
+        background-image url("../img/admonitions/warning.png")
+    div.error
+        background-image url("../img/admonitions/warning.png")
+    div.hint
+        background-image url("../img/admonitions/tip.png")
     div.important
         background-image url("../img/admonitions/important.png")
     div.note
     div.warning
         background-image url("../img/admonitions/warning.png")
 
-    div.caution, div.important, div.note, div.tip, div.warning
+    div.attention, div.caution, div.danger, div.error, div.hint, div.important, div.note, div.tip, div.warning
         color black
         background-color #F9F9FF
         background-repeat no-repeat