Discussion:
[reportlab-users] xml parser error (invalid attribute name class) in paragraph
Jon.Reinsch
2012-12-12 18:09:44 UTC
Permalink
I developed code using ReportLab 2.5, but after upgrading to 2.6, it
fails. An extremely stripped-down version is:
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import *
classrowstyle =
ParagraphStyle(name="classrowstyle",fontSize=8,fontName="Helvetica",leading=11)
row1 = '<span class="protected">simplified</span>'
details = Paragraph(row1,classrowstyle)

The error is as follows:
Traceback (most recent call last):
File "C:\MiniESI\bugtest.py", line 6, in <module>
details = Paragraph(row1,classrowstyle)
File "C:\Python27\lib\site-packages\reportlab\platypus\paragraph.py",
line 919, in __init__
self._setup(text, style, bulletText or
getattr(style,'bulletText',None), frags, cleanBlockQuoted
Text)
File "C:\Python27\lib\site-packages\reportlab\platypus\paragraph.py",
line 937, in _setup
% (_parser.errors[0],text[:min(30,len(text))]))
ValueError: xml parser error (invalid attribute name class) in paragraph
beginning
'<span class="protected">simpli'

As I said, my code ran fine in ReportLab 2.5. Thanks for any advice you
can offer.
--
Jon Reinsch
National Oceanic and Atmospheric Administration, Seattle
Robin Becker
2012-12-13 12:24:24 UTC
Permalink
Post by Jon.Reinsch
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import *
classrowstyle =
ParagraphStyle(name="classrowstyle",fontSize=8,fontName="Helvetica",leading=11)
row1 = '<span class="protected">simplified</span>'
details = Paragraph(row1,classrowstyle)
I'm not sure exactly when you developed your solution, but between the release
of 2.5 and 2.6 (11 November 2011) we added support for the <span> tag. However
we don't support class as an attribute, but we do support style.

I have checked your example in revision 3774 (just prior to the change) and
while it works it takes no notice of the span tag ie only the content of the tag
'simplified' appears in the output.

Currently our 'span' supports various attributes, but not class. We have argued
internally for an hour about the wisdom of adding the 'span' tag and not having
an exact html match for all attributes, but the tag is now added and doesn't
support all html attributes.

An easy fix would be to allow unknown attributes and just ignore them. I'll
consult my colleagues about the possibility of doing that as a fix for your problem.
--
Robin Becker
Robin Becker
2012-12-13 12:49:56 UTC
Permalink
I developed code using ReportLab 2.5, but after upgrading to 2.6, it fails. An
....
As I said, my code ran fine in ReportLab 2.5. Thanks for any advice you can offer.
A quick fix for your issue is to modify the file

reportlab/platypus/paraparser.py using this patch

Index: reportlab/platypus/paraparser.py
===================================================================
--- reportlab/platypus/paraparser.py (revision 3986)
+++ reportlab/platypus/paraparser.py (working copy)
@@ -166,6 +166,7 @@
'backcolor':('backColor',toColor),
'bgcolor':('backColor',toColor),
'style': ('style',None),
+ 'class': ('',None),
}
#things which are valid font attributes
_linkAttrMap = {'size': ('fontSize', _num),


which modifies the _spanAttrMap definition.
--
Robin Becker
Jon.Reinsch
2012-12-14 19:00:19 UTC
Permalink
Well, given that it was simply ignored in 2.5, I might as well remove
the class attribute from my markup, rather than apply the patch. "style"
doesn't seem to work either (I get "ValueError: findSpanStyle not
implemented in this parser"). However, something that didn't work in 2.5
(font backColor="yellow") is now supported. Without the exception on the
class attribute, I probably wouldn't have discovered this. Thanks!
Post by Robin Becker
I developed code using ReportLab 2.5, but after upgrading to 2.6, it fails. An
....
As I said, my code ran fine in ReportLab 2.5. Thanks for any advice you can offer.
A quick fix for your issue is to modify the file
reportlab/platypus/paraparser.py using this patch
Index: reportlab/platypus/paraparser.py
===================================================================
--- reportlab/platypus/paraparser.py (revision 3986)
+++ reportlab/platypus/paraparser.py (working copy)
@@ -166,6 +166,7 @@
'backcolor':('backColor',toColor),
'bgcolor':('backColor',toColor),
'style': ('style',None),
+ 'class': ('',None),
}
#things which are valid font attributes
_linkAttrMap = {'size': ('fontSize', _num),
which modifies the _spanAttrMap definition.
Robin Becker
2012-12-17 13:41:14 UTC
Permalink
Well, given that it was simply ignored in 2.5, I might as well remove the class
attribute from my markup, rather than apply the patch. "style" doesn't seem to
work either (I get "ValueError: findSpanStyle not implemented in this parser").
However, something that didn't work in 2.5 (font backColor="yellow") is now
supported. Without the exception on the class attribute, I probably wouldn't
have discovered this. Thanks!
well some good came out of this then. As for the style="...." that is in fact
equivalent in some ways to class in html. The standard parser doesn't implement
findSpanStyle, but derived parsers can choose to do so. The findSpanStyle method
should return a dictionary like object when given the style attribute. Currently
the only implementation is in rml2pdf. The returned object can specify all or
none of fontName fontSize textColor backColor etc etc.
Post by Robin Becker
I developed code using ReportLab 2.5, but after upgrading to 2.6, it fails. An
....
A quick fix for your issue is to modify the file
.......efinition.
--
Robin Becker
Loading...