###
# Czechtile: WikiHezkyCesky
# Copyright (C) 2006 Lukas "Almad" Linhart http://www.almad.net/
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
###

from czechtile import nodes
from czechtile.expanders import entities
from czechtile.expanders.base import CzechtileExpander, EmptyExpander, ExpanderMap, TextNodeExpander

class Document(EmptyExpander): pass
class Book(EmptyExpander): pass
class Article(EmptyExpander): pass
class Sekce(EmptyExpander): pass

class Nadpis(CzechtileExpander):
    def expand(self, node, format, node_map):
        return self.expand_with_content(node, format, node_map, u'=' * node.level, u'=' * node.level)

class Odstavec(CzechtileExpander):
    def expand(self, node, format, node_map):
        return self.expand_with_content(node, format, node_map, u'', u'\n\n')

class NeformatovanyText(CzechtileExpander):
    def expand(self, node, format, node_map):
        return self.expand_with_content(node, format, node_map, u'<pre>', u'</pre>')

class Silne(CzechtileExpander):
    def expand(self, node, format, node_map):
        return self.expand_with_content(node, format, node_map, u"'''", u"'''")

class Zvyraznene(CzechtileExpander):
    def expand(self, node, format, node_map):
        return self.expand_with_content(node, format, node_map, u"''", u"''")

class Hyperlink(CzechtileExpander):
    def expand(self, node, format, node_map):
        return self.expand_with_content(node, format, node_map, u'[%s ' % unicode(node.link), u']')

# TODO
class List(EmptyExpander): pass
class ListItem(EmptyExpander): pass

#class List(ListExpander):
    #types = {
        #'itemized': (u'*',),
        #'1-ordered': (u'#',),
        #'A-ordered': (u'#',),
        #'I-ordered': (u'#',)
    #}
    #tag_formats = {'start': u'%s', 'end': u''}

#class ListItem(ListItemExpander):
    #list_expander = List
    #tag = (u'*',)

class Preskrtnute(CzechtileExpander):
    def expand(self, node, format, node_map):
        return self.expand_with_content(node, format, node_map,
          u'<s>', u'</s>')

class Obrazek(CzechtileExpander):
    def expand(self, node, format, node_map):
        return '[[Image:%s]]' % node.source

map = ExpanderMap({
    nodes.DocumentNode: Document,
    nodes.TextNode: TextNodeExpander,

    nodes.Book: Book,
    nodes.Article: Article,
    nodes.Nadpis: Nadpis,
    nodes.Odstavec: Odstavec,
    nodes.NeformatovanyText: NeformatovanyText,
    nodes.Silne: Silne,
    nodes.Zvyraznene: Zvyraznene,
    nodes.TriTecky: entities.TriTecky,
    nodes.Pomlcka: entities.Pomlcka,
    nodes.Hyperlink: Hyperlink,
    nodes.List: List,
    nodes.ListItem: ListItem,
    nodes.Uvozovky: entities.Uvozovky,
    nodes.PevnaMedzera: entities.PevnaMedzera,
    nodes.Preskrtnute: Preskrtnute,
    nodes.Obrazek: Obrazek
})
@@ -2159,15 +2159,8 @@
 ')%0A%0A
-# TODO%0A
 clas
@@ -2166,21 +2166,25 @@
 ss List(
-Empty
+Czechtile
 Expander
@@ -2189,122 +2189,109 @@
 er):
- pass%0Aclass ListItem(EmptyExpander): pass%0A%0A#class List(ListExpander
+%0A    def expand(self, node, format, node_map
 ):%0A    
-#types = %7B%0A        #'itemized': (
+    if node.token == '-':%0A            token = 
 u'*'
-,),
 %0A   
@@ -2299,30 +2299,38 @@
     
-#'1-ordered': (
+else:%0A            token = 
 u'#'
-,),
 %0A   
@@ -2338,118 +2338,236 @@
     
-#'A-ordered': (u'#',),%0A        #'I-ordered': (u'#',
+res = self.expand_with_content(node, format, node_map)%0A        res = u''.join(%5Btoken + r + u'%5Cn' for r in res.split('%5Cn') if r%5D
 )%0A    
-#%7D%0A
     
-#tag_formats = %7B'start': u'%25s', 'end': u''%7D
+if not isinstance(node.parent, nodes.List):%0A            res = res%5B:-1%5D%0A        return res
 %0A%0A
-#
 clas
@@ -2577,24 +2577,25 @@
 istItem(
-ListItem
+Czechtile
 Expander
@@ -2605,47 +2605,125 @@
     
-#list_expander = List%0A    #tag = (u'*
+def expand(self, node, format, node_map):%0A        return self.expand_with_content(node, format, node_map, u' 
 ',
+ u'%5Cn'
 )%0A%0Ac
@@ -2992,16 +2992,17 @@
  return 
+u
 '%5B%5BImage

Add MediaWiki list expanders