summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2010-11-12 13:04:33 +0100
committerJan Holesovsky <kendy@suse.cz>2010-11-12 13:04:33 +0100
commit85613f119bc3d60e1ab067b4b4c370c3e0fc1321 (patch)
treefa094d14465c84e288c327d82068973842c7d2cb
parent0e5e9fa9419bfe375db7d8c66712a1c7434bac36 (diff)
wikihelp: Handle lists.
-rwxr-xr-xhelpcontent2/to-wiki/getalltitles.py7
-rwxr-xr-xhelpcontent2/to-wiki/wikiconv2.py93
2 files changed, 99 insertions, 1 deletions
diff --git a/helpcontent2/to-wiki/getalltitles.py b/helpcontent2/to-wiki/getalltitles.py
index a6d7d036d7..f4034ab34d 100755
--- a/helpcontent2/to-wiki/getalltitles.py
+++ b/helpcontent2/to-wiki/getalltitles.py
@@ -107,7 +107,12 @@ def parsexhp(filename):
p.EndElementHandler = end_element
p.CharacterDataHandler = char_data
buf = file.read()
- p.Parse(buf)
+ try:
+ p.Parse(buf)
+ except:
+ sys.stderr.write('Cannot parse %s, skipping it\n'% filename)
+ file.close()
+ return
file.close()
if len(title):
readable_title = readable_text(title)
diff --git a/helpcontent2/to-wiki/wikiconv2.py b/helpcontent2/to-wiki/wikiconv2.py
index 0d4979ca41..b036b81422 100755
--- a/helpcontent2/to-wiki/wikiconv2.py
+++ b/helpcontent2/to-wiki/wikiconv2.py
@@ -24,6 +24,8 @@ replace_paragraph_role = \
'heading4': '==== ',
'heading5': '===== ',
'heading6': '====== ',
+ 'listitem': '',
+ 'note': '{{Note|',
'paragraph': '',
'tablecontent': '| ',
'tablehead': '! scope="col" | ',
@@ -36,6 +38,8 @@ replace_paragraph_role = \
'heading4': ' ====\n\n',
'heading5': ' =====\n\n',
'heading6': ' ======\n\n',
+ 'listitem': '\n',
+ 'note': '}}\n\n',
'paragraph': '\n\n',
'tablecontent': '\n\n',
'tablehead': '\n\n',
@@ -152,6 +156,11 @@ class cxml:
self.child_parsing = True
self.objects.append(child)
+ if name == 'list':
+ child = clist(attrs, self)
+ self.child_parsing = True
+ self.objects.append(child)
+
if name == 'bookmark':
child = cbookmark(attrs, self)
self.child_parsing = True
@@ -367,6 +376,90 @@ class ctable:
return self.objects[len(self.objects)-1].get_curobj()
return self
+class clistitem:
+ def __init__(self, attrs, parent):
+ # TODO: colspan rowspan
+ self.objects = []
+ self.child_parsing = False
+ self.parent = parent
+
+ def start_element(self, name, attrs):
+ if name == 'paragraph':
+ para = cparagraph(attrs, self, '', 0)
+ self.child_parsing = True
+ self.objects.append(para)
+
+ def end_element(self, name):
+ if name == 'listitem':
+ self.parent.child_parsing = False
+
+ def char_data(self, data):
+ return
+
+ def get_all(self):
+ text = ""
+ prefix = '*'
+ postfix = ''
+ if self.parent.startwith > 0:
+ prefix = '<li>'
+ postfix = '</li>'
+ elif self.parent.type == 'ordered':
+ prefix = '#'
+
+ # add the text itself
+ for i in self.objects:
+ text = text + prefix + i.get_all() + postfix
+
+ return text
+
+ def get_curobj(self):
+ if self.child_parsing:
+ return self.objects[len(self.objects)-1].get_curobj()
+ return self
+
+class clist:
+ def __init__(self, attrs, parent):
+ self.objects = []
+ self.child_parsing = False
+ self.parent = parent
+ self.type = attrs['type']
+ try:
+ self.startwith = int(attrs['startwith'])
+ except:
+ self.startwith = 0
+
+ def start_element(self, name, attrs):
+ if name == 'listitem':
+ listitem = clistitem(attrs, self)
+ self.child_parsing = True
+ self.objects.append(listitem)
+
+ def end_element(self, name):
+ if name == 'list':
+ self.parent.child_parsing = False
+
+ def char_data(self, data):
+ return
+
+ def get_all(self):
+ text = ""
+ if self.startwith > 0:
+ text = text + '<ol start="%d">\n'% self.startwith
+
+ for i in self.objects:
+ text = text + i.get_all()
+
+ if self.startwith > 0:
+ text = text + '</ol>\n'
+ else:
+ text = text + '\n'
+ return text
+
+ def get_curobj(self):
+ if self.child_parsing:
+ return self.objects[len(self.objects)-1].get_curobj()
+ return self
+
class clink:
def __init__(self, attrs, parent):
self.link = attrs['href']