diff options
-rw-r--r-- | talinterpreter.py | 19 | ||||
-rw-r--r-- | tests/output/test_sa2.html | 8 | ||||
-rw-r--r-- | tests/output/test_sa2.xml | 8 | ||||
-rw-r--r-- | tests/test_talinterpreter.py | 12 |
4 files changed, 19 insertions, 28 deletions
diff --git a/talinterpreter.py b/talinterpreter.py index af46fa8..9df6a84 100644 --- a/talinterpreter.py +++ b/talinterpreter.py @@ -102,9 +102,8 @@ class TALInterpreter: 1. setPosition bytecode follows setSourceFile, and we need position information to output the line number. - 2. Mozilla does not cope with HTML comments that occur before - <!DOCTYPE> (XXX file a bug into bugzilla.mozilla.org as comments - are legal there according to HTML4 spec). + 2. Comments are not allowed in XML documents before the <?xml?> + declaration. For performance reasons (XXX premature optimization?) instead of checking the value of _pending_source_annotation on every write to the output @@ -257,17 +256,13 @@ class TALInterpreter: self._stream_write = self.stream.write def _annotated_stream_write(self, s): - idx = s.find('<!DOCTYPE') - if idx == -1: - idx = s.find('<?xml') + idx = s.find('<?xml') if idx >= 0 or s.isspace(): - # Do *not* preprend comments in front of the <!DOCTYPE> or - # <?xml?> declaration! Although that is completely legal according - # to w3c.org, Mozilla chokes on such pages. - end_of_doctype = s.find('>', idx) + # Do not preprend comments in front of the <?xml?> declaration. + end_of_doctype = s.find('?>', idx) if end_of_doctype > idx: - self.stream.write(s[:end_of_doctype+1]) - s = s[end_of_doctype+1:] + self.stream.write(s[:end_of_doctype+2]) + s = s[end_of_doctype+2:] # continue else: self.stream.write(s) diff --git a/tests/output/test_sa2.html b/tests/output/test_sa2.html index 0fc0d93..4709b49 100644 --- a/tests/output/test_sa2.html +++ b/tests/output/test_sa2.html @@ -1,10 +1,10 @@ -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "DTD/xhtml1-transitional.dtd"><!-- +<!-- ============================================================================== tests/input/test_sa2.html ============================================================================== ---> +--><!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "DTD/xhtml1-transitional.dtd"> <html> <title>Simple test of source annotations</title> <body> diff --git a/tests/output/test_sa2.xml b/tests/output/test_sa2.xml index 59a3c07..30b5699 100644 --- a/tests/output/test_sa2.xml +++ b/tests/output/test_sa2.xml @@ -1,11 +1,11 @@ -<?xml version="1.0" ?> -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "DTD/xhtml1-transitional.dtd"><!-- +<?xml version="1.0" ?><!-- ============================================================================== tests/input/test_sa2.xml ============================================================================== --> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "DTD/xhtml1-transitional.dtd"> <html> <title>Simple test of source annotations</title> <body> diff --git a/tests/test_talinterpreter.py b/tests/test_talinterpreter.py index 29251f0..fb8893f 100644 --- a/tests/test_talinterpreter.py +++ b/tests/test_talinterpreter.py @@ -410,15 +410,11 @@ class TestSourceAnnotations(unittest.TestCase): test_cases = [ '@some text', '\n', - '<!DOCTYPE ...>@some text', - ' <!DOCTYPE ...>@some text', - '\n<!DOCTYPE ...>@some text', - '<!DOCTYPE ...', - '<?xml ...>@some text', - ' <?xml ...>@some text', - '\n<?xml ...>@some text', + '<?xml ...?>@some text', + ' <?xml ...?>@some text', + '\n<?xml ...?>@some text', '<?xml ...', - '<?xml ...?>\n<!DOCTYPE ...>@some text', + '<?xml ...?>@\n<!DOCTYPE ...>some text', ] for output in test_cases: input = output.replace('@', '') |