Solved partially bug https://bugs.launchpad.net/appy/+bug/394258 (rendering of the content of style tags)

This commit is contained in:
Gaetan Delannay 2009-08-11 15:43:21 +02:00
parent b4d2360d6f
commit bdb220716c
4 changed files with 1583 additions and 1546 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
xhtmlInput = '''
<p><meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" /><title></title><meta name="GENERATOR" content="OpenOffice.org 3.0 (Win32)" /><style type="text/css">
&lt;!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
--&gt;
</style>
<p>concepteurs de normes : membres des
cabinets ministériels et les administrations.</p>
<p><br /><br /></p>
<p>Laurent, membre du cabinet du Ministre
de l'énergie, doit rédiger un arrêté du Gouvernement wallon
relatif à l'octroi d'une prime à l'isolation. Il peut télécharger
le canevas typ</p>
</p>'''

Binary file not shown.

View file

@ -35,6 +35,7 @@ TABLE_CELL_TAGS = ('td', 'th')
OUTER_TAGS = TABLE_CELL_TAGS + ('li',) OUTER_TAGS = TABLE_CELL_TAGS + ('li',)
NOT_INSIDE_P = ('table', 'ol', 'ul') # Those elements can't be rendered inside NOT_INSIDE_P = ('table', 'ol', 'ul') # Those elements can't be rendered inside
# paragraphs. # paragraphs.
IGNORABLE_TAGS = ('meta', 'title', 'style')
HTML_ENTITIES = { HTML_ENTITIES = {
'iexcl': '¡', 'cent': '¢', 'pound': '£', 'curren': '', 'yen': '¥', 'iexcl': '¡', 'cent': '¢', 'pound': '£', 'curren': '', 'yen': '¥',
'brvbar': 'Š', 'sect': '§', 'uml': '¨', 'copy':'©', 'ordf':'ª', 'brvbar': 'Š', 'sect': '§', 'uml': '¨', 'copy':'©', 'ordf':'ª',
@ -175,6 +176,8 @@ class XhtmlEnvironment(XmlEnvironment):
self.textNs = ns[OdfEnvironment.NS_TEXT] self.textNs = ns[OdfEnvironment.NS_TEXT]
self.linkNs = ns[OdfEnvironment.NS_XLINK] self.linkNs = ns[OdfEnvironment.NS_XLINK]
self.tableNs = ns[OdfEnvironment.NS_TABLE] self.tableNs = ns[OdfEnvironment.NS_TABLE]
self.ignore = False # Will be True when parsing parts of the XHTML that
# must be ignored.
def getCurrentElement(self, isList=False): def getCurrentElement(self, isList=False):
'''Gets the element that is on the top of self.currentElements or '''Gets the element that is on the top of self.currentElements or
@ -413,6 +416,8 @@ class XhtmlParser(XmlParser):
e.dumpString(' %s:number-columns-spanned="%s"' % \ e.dumpString(' %s:number-columns-spanned="%s"' % \
(e.tableNs, attrs['colspan'])) (e.tableNs, attrs['colspan']))
e.dumpString('>') e.dumpString('>')
elif elem in IGNORABLE_TAGS:
e.ignore = True
def endElement(self, elem): def endElement(self, elem):
elem = self.lowerizeInput(elem) elem = self.lowerizeInput(elem)
@ -439,12 +444,15 @@ class XhtmlParser(XmlParser):
e.dumpString('</%s:table-row>' % e.tableNs) e.dumpString('</%s:table-row>' % e.tableNs)
elif elem in TABLE_CELL_TAGS: elif elem in TABLE_CELL_TAGS:
e.dumpString('</%s:table-cell>' % e.tableNs) e.dumpString('</%s:table-cell>' % e.tableNs)
elif elem in IGNORABLE_TAGS:
e.ignore = False
if elemsToReopen: if elemsToReopen:
e.dumpString(elemsToReopen) e.dumpString(elemsToReopen)
def characters(self, content): def characters(self, content):
e = XmlParser.characters(self, content) e = XmlParser.characters(self, content)
e.currentContent += content if not e.ignore:
e.currentContent += content
# ------------------------------------------------------------------------------- # -------------------------------------------------------------------------------
class Xhtml2OdtConverter: class Xhtml2OdtConverter: