summaryrefslogtreecommitdiff
path: root/helpcontent2/to-wiki/wikiconv2.py
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2010-12-09 14:20:25 +0100
committerJan Holesovsky <kendy@suse.cz>2010-12-09 14:20:25 +0100
commit23b8f6e088db9b7e012b63fca29a9abc396043db (patch)
tree919ec926ee79d6dede856738cd48ccf8fe073187 /helpcontent2/to-wiki/wikiconv2.py
parent00d5b2ca4802ba02e4003a0b98f01f021ad6dc9f (diff)
wikihelp: Don't create "''''''" artefacts. Improve images in lists.
Diffstat (limited to 'helpcontent2/to-wiki/wikiconv2.py')
-rwxr-xr-xhelpcontent2/to-wiki/wikiconv2.py64
1 files changed, 38 insertions, 26 deletions
diff --git a/helpcontent2/to-wiki/wikiconv2.py b/helpcontent2/to-wiki/wikiconv2.py
index 464c36512e..06a5fb118a 100755
--- a/helpcontent2/to-wiki/wikiconv2.py
+++ b/helpcontent2/to-wiki/wikiconv2.py
@@ -23,21 +23,11 @@ redirects = []
# to collect images that we will up-load later
images = set()
-# list of elements that we can directly convert to wiki text
-replace_element = \
- {'start':{'br': '<br/>',
- 'emph': "'''",
- 'help-id-missing': "'''Missing help ID.'''"
- },
- 'end': {'br': '',
- 'emph': "'''",
- 'help-id-missing': ""
- }
- }
-
+# various types of paragraphs
replace_paragraph_role = \
{'start':{'code': '<code>',
'codeintip': '<code>',
+ 'emph' : '', # must be empty to be able to strip empty <emph/>
'example': '<code>',
'heading1': '= ',
'heading2': '== ',
@@ -60,6 +50,7 @@ replace_paragraph_role = \
},
'end':{'code': '</code>\n\n',
'codeintip': '</code>\n\n',
+ 'emph' : '',
'example': '</code>\n\n',
'heading1': ' =\n\n',
'heading2': ' ==\n\n',
@@ -82,6 +73,7 @@ replace_paragraph_role = \
},
'templ':{'code': False,
'codeintip': False,
+ 'emph' : False,
'example': False,
'heading1': False,
'heading2': False,
@@ -498,10 +490,18 @@ class Image(ElementBase):
def get_curobj(self):
return self
+class Br(TextElementBase):
+ def __init__(self, attrs, parent):
+ TextElementBase.__init__(self, attrs, parent, 'br', '<br/>', '', False)
+
class Comment(TextElementBase):
def __init__(self, attrs, parent):
TextElementBase.__init__(self, attrs, parent, 'comment', '<!-- ', ' -->', False)
+class HelpIdMissing(TextElementBase):
+ def __init__(self, attrs, parent):
+ TextElementBase.__init__(self, attrs, parent, 'help-id-missing', '{{MissingHelpId}}', '', False)
+
class Text:
def __init__(self, text):
self.wikitext = replace_text(text)
@@ -624,7 +624,7 @@ class List(ElementBase):
text = text + ElementBase.get_all(self)
if self.startwith > 0:
- text = text + '</ol>\n'
+ text = text + '\n</ol>\n'
else:
text = text + '\n'
return text
@@ -961,12 +961,18 @@ class Paragraph(ElementBase):
# TODO extended tips are ignored for now, just the text is used
# verbatim
pass
+ elif name == 'br':
+ self.parse_child(Br(attrs, self))
elif name == 'comment':
self.parse_child(Comment(attrs, self))
+ elif name == 'emph':
+ self.parse_child(Emph(attrs, self))
elif name == 'embedvar':
if parser.follow_embed:
(fname, id) = href_to_fname_id(attrs['href'])
self.embed_href(parser, fname, id)
+ elif name == 'help-id-missing':
+ self.parse_child(HelpIdMissing(attrs, self))
elif name == 'image':
self.parse_child(Image(attrs, self))
elif name == 'item':
@@ -978,21 +984,11 @@ class Paragraph(ElementBase):
elif name == 'variable':
self.parse_child(Variable(attrs, self))
else:
- try:
- global replace_element
- self.objects.append(Text(replace_element['start'][name]))
- except:
- self.unhandled_element(parser, name)
+ self.unhandled_element(parser, name)
def end_element(self, parser, name):
ElementBase.end_element(self, parser, name)
- try:
- global replace_element
- self.objects.append(Text(replace_element['end'][name]))
- except:
- pass
-
def char_data(self, parser, data):
if self.role == 'paragraph' or self.role == 'heading' or \
self.role == 'listitem':
@@ -1037,10 +1033,14 @@ class Paragraph(ElementBase):
sys.stderr.write( "Unknown paragraph role start: " + role + "\n" )
# the text itself
+ children = ElementBase.get_all(self)
+ if self.role != 'emph':
+ children = children.strip()
+
if replace_paragraph_role['templ'][role]:
- text = text + escape_equals_sign(ElementBase.get_all(self).strip())
+ text = text + escape_equals_sign(children)
else:
- text = text + ElementBase.get_all(self).strip()
+ text = text + children
# append the markup according to the role
if len(self.objects) > 0:
@@ -1074,6 +1074,18 @@ class CaseInline(Paragraph):
self.name = 'caseinline'
self.case = attrs['select']
+class Emph(Paragraph):
+ def __init__(self, attrs, parent):
+ Paragraph.__init__(self, attrs, parent)
+ self.name = 'emph'
+ self.role = 'emph'
+
+ def get_all(self):
+ text = Paragraph.get_all(self)
+ if len(text):
+ return "'''" + text + "'''"
+ return ''
+
class ListItemParagraph(Paragraph):
def __init__(self, attrs, parent):
Paragraph.__init__(self, attrs, parent)