773 |
773 |
774 |
774 |
775 @nocoverage |
775 @nocoverage |
776 def _check_html(self, output, view, template='main-template'): |
776 def _check_html(self, output, view, template='main-template'): |
777 """raises an exception if the HTML is invalid""" |
777 """raises an exception if the HTML is invalid""" |
|
778 output = output.strip() |
778 try: |
779 try: |
779 validatorclass = self.vid_validators[view.__regid__] |
780 validatorclass = self.vid_validators[view.__regid__] |
780 except KeyError: |
781 except KeyError: |
781 if view.content_type in ('text/html', 'application/xhtml+xml'): |
782 if view.content_type in ('text/html', 'application/xhtml+xml'): |
782 if template is None: |
783 if output.startswith('<?xml'): |
|
784 default_validator = htmlparser.DTDValidator |
|
785 else: |
783 default_validator = htmlparser.HTMLValidator |
786 default_validator = htmlparser.HTMLValidator |
784 else: |
|
785 default_validator = htmlparser.DTDValidator |
|
786 else: |
787 else: |
787 default_validator = None |
788 default_validator = None |
788 validatorclass = self.content_type_validators.get(view.content_type, |
789 validatorclass = self.content_type_validators.get(view.content_type, |
789 default_validator) |
790 default_validator) |
790 if validatorclass is None: |
791 if validatorclass is None: |
791 return output.strip() |
792 return |
792 validator = validatorclass() |
793 validator = validatorclass() |
793 if isinstance(validator, htmlparser.DTDValidator): |
794 if isinstance(validator, htmlparser.DTDValidator): |
794 # XXX remove <canvas> used in progress widget, unknown in html dtd |
795 # XXX remove <canvas> used in progress widget, unknown in html dtd |
795 output = re.sub('<canvas.*?></canvas>', '', output) |
796 output = re.sub('<canvas.*?></canvas>', '', output) |
796 return validator.parse_string(output.strip()) |
797 return validator.parse_string(output.strip()) |