make reporting unbalanced tags an overridable method
This commit is contained in:
parent
b47281539a
commit
efe5ac404f
|
@ -226,8 +226,8 @@ class SGMLParser:
|
||||||
if self.stack and self.stack[-1] == tag:
|
if self.stack and self.stack[-1] == tag:
|
||||||
del self.stack[-1]
|
del self.stack[-1]
|
||||||
else:
|
else:
|
||||||
print '*** Unbalanced </' + tag + '>'
|
self.report_unbalanced(tag)
|
||||||
print '*** Stack:', self.stack
|
# Now repair it
|
||||||
found = None
|
found = None
|
||||||
for i in range(len(self.stack)):
|
for i in range(len(self.stack)):
|
||||||
if self.stack[i] == tag: found = i
|
if self.stack[i] == tag: found = i
|
||||||
|
@ -235,6 +235,11 @@ class SGMLParser:
|
||||||
del self.stack[found:]
|
del self.stack[found:]
|
||||||
method()
|
method()
|
||||||
|
|
||||||
|
# Example -- report an unbalanced </...> tag.
|
||||||
|
def report_unbalanced(self, tag):
|
||||||
|
print '*** Unbalanced </' + tag + '>'
|
||||||
|
print '*** Stack:', self.stack
|
||||||
|
|
||||||
# Example -- handle character reference, no need to override
|
# Example -- handle character reference, no need to override
|
||||||
def handle_charref(self, name):
|
def handle_charref(self, name):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue