@@ -381,6 +381,37 @@ def getStartTag(self, *args, **kwargs):
381381
382382 return ret
383383
384+ def handle_starttag_slim (self , tagName , attributeList , isSelfClosing = False ):
385+ '''
386+ handle_starttag_slim - Handles parsing a start tag, but with "slim" start tags
387+
388+ @see AdvancedHTMLFormatter.handle_starttag
389+ '''
390+ tagName = tagName .lower ()
391+ inTag = self ._inTag
392+
393+ if isSelfClosing is False and tagName in IMPLICIT_SELF_CLOSING_TAGS :
394+ isSelfClosing = True
395+
396+ newTag = AdvancedTagSlim (tagName , attributeList , isSelfClosing , slimSelfClosing = self .slimSelfClosing )
397+ if self .root is None :
398+ self .root = newTag
399+ elif len (inTag ) > 0 :
400+ inTag [- 1 ].appendChild (newTag )
401+ else :
402+ raise MultipleRootNodeException ()
403+
404+ if self .inPreformatted is 0 :
405+ newTag ._indent = self ._getIndent ()
406+
407+ if tagName in PREFORMATTED_TAGS :
408+ self .inPreformatted += 1
409+
410+ if isSelfClosing is False :
411+ inTag .append (newTag )
412+ if tagName != INVISIBLE_ROOT_TAG :
413+ self .currentIndentLevel += 1
414+
384415
385416class AdvancedHTMLSlimTagFormatter (AdvancedHTMLFormatter ):
386417 '''
@@ -410,36 +441,8 @@ def __init__(self, indent=' ', encoding='utf-8', slimSelfClosing=False):
410441
411442 self .slimSelfClosing = slimSelfClosing
412443
413- def handle_starttag (self , tagName , attributeList , isSelfClosing = False ):
414- '''
415- handle_starttag - Handles parsing a start tag.
416-
417- @see AdvancedHTMLFormatter.handle_starttag
418- '''
419- tagName = tagName .lower ()
420- inTag = self ._inTag
421-
422- if isSelfClosing is False and tagName in IMPLICIT_SELF_CLOSING_TAGS :
423- isSelfClosing = True
424444
425- newTag = AdvancedTagSlim (tagName , attributeList , isSelfClosing , slimSelfClosing = self .slimSelfClosing )
426- if self .root is None :
427- self .root = newTag
428- elif len (inTag ) > 0 :
429- inTag [- 1 ].appendChild (newTag )
430- else :
431- raise MultipleRootNodeException ()
432-
433- if self .inPreformatted is 0 :
434- newTag ._indent = self ._getIndent ()
435-
436- if tagName in PREFORMATTED_TAGS :
437- self .inPreformatted += 1
438-
439- if isSelfClosing is False :
440- inTag .append (newTag )
441- if tagName != INVISIBLE_ROOT_TAG :
442- self .currentIndentLevel += 1
445+ handle_starttag = handle_starttag_slim
443446
444447
445448class AdvancedHTMLSlimTagMiniFormatter (AdvancedHTMLMiniFormatter ):
@@ -465,7 +468,7 @@ def __init__(self, encoding='utf-8', slimSelfClosing=False):
465468
466469 self .slimSelfClosing = slimSelfClosing
467470
468- handle_starttag = AdvancedHTMLSlimTagFormatter . handle_starttag
471+ handle_starttag = handle_starttag_slim
469472
470473
471474#vim: set ts=4 sw=4 expandtab
0 commit comments