In my kid template I have this following line: <div
class="reviewitem" py:content="XML(review.Content)" />.
My problem is when the XML() argument is not a very clean html
string, XML fail miserably.
How can I manage to roughly clean that string (in the template) or at
least return the string not formated, instead of having an exception
thrown.
Thanks
-fred-
But if the HTML isn't valid, you may have trouble rendering it no
matter what you do.
--
Mark Ramm-Christensen
email: mark at compoundthinking dot com
blog: www.compoundthinking.com/blog
-- Sven
class XHTMLValidator(validators.FancyValidator):
def _to_python(self, value, state = None):
try:
template = kid.Template(
"""<html xmlns:py="http://purl.org/kid/ns#">%s</html>"""
% value)
except Exception, e:
raise validators.Invalid( e.args[0], value, state)
s = template.serialize( output = "xml")
return s[s.index("<html>")+6:-7]
It uses a temporary template to check the XHTML code for correctness,
feeds errors back as
validation errors and extracts the cleaned-up XHTML markup from the
serialized output.
-- Sven
My suggestion was a bit tongue in cheek ;) It's the only way I know
of to 100% avoid KID while using KID. And while you can get around
Kid's validation that way, I don't particularly think it's a good idea
either. But I thought I'd throw it out there in case you were
looking for an ugly hack.
What I should have mentioned is that an easier way to get around KID
in a situation like this is not to use KID at all. You can use
Cheetah instead, and get around KID's validity requirement. Cheetah
shouldn't care a bit about how broken your HTML is.
Automatic HTML repair sounds like it would be nice, and perhaps it's
possible for some subset of HTML errors, but I doubt it's really
feasible unless your HTML is already almost right, and is broken an
easy to detect way. It seems like your best choice is to go to the
source, and see if you can fix that.
--Mark
I agree. I never said it was good, and I even said that it probably
wouldn't work! But it's the only ugly hack I could think of to get
done what Fred was asking for.
The right answer is exactly what you say. Don't use KID when you want
to have invalid output. The right thing to do is to create valid
output, but if that's not possible the second best thing is to use
Cheetah, or one of the other available templates with TurboGears
plugins that doesn't care about validity.
Hello,
In my kid template I have this following line: <div
class="reviewitem" py:content="XML(review.Content)" />.
My problem is when the XML() argument is not a very clean html
string, XML fail miserably.
How can I manage to roughly clean that string (in the template) or at
least return the string not formated, instead of having an exception
thrown.
Thanks
-fred-
I think you are right and I am going to use Cheetah instead of kid. I
like kid and I like the fact that it forces you to write clean code,
but it can be a pain when you get part of your html content from a
third party with a lot of small errors.
I have try to cleanup this code with ElementTidy, but this tool is
not design to clean up a single string. It did not gave me the result
expected. For fixing the source this is impossible, the only thing I
can do with the source is read it. And I don't think the people who
are producing that source gonna start closing the </p> , </li> or
other tags who are not really affecting the presentation on their
browsers.
Thanks for you answer.
-fred-
> I think you are right and I am going to use Cheetah instead of kid. I
> like kid and I like the fact that it forces you to write clean code,
> but it can be a pain when you get part of your html content from a
> third party with a lot of small errors.
Not to mention when it mangles your code by putting spaces between images when
you don't want them. How does one change templates? I think I'm more
interested in Myghty.
Mike
--
Michael P. Soulier <msou...@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction." --Albert Einstein
It's quite good at producing valid markup out of invalid markup (in
terms of matching tags and stuff).
It's not very quick, but it can handle very bad markup.
Ed
On 6/11/06, Fred C <bsd...@gmail.com> wrote:
>
>