Skip to content

Commit 57a1388

Browse files
committed
Note the SlimTagFormatter s in README
1 parent 2dbbb9e commit 57a1388

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,57 @@ Use this when pretty-printing doesn't matter and you'd like to save space.
412412
You can access this same formatting off an AdvancedHTMLParser.AdvancedHTMLParser (or IndexedAdvancedHTMLParser) by calling .getMiniHTML()
413413

414414

415+
**AdvancedHTMLSlimTagFormatter and AdvancedHTMLSlimTagMiniFormatter**
416+
417+
In order to support some less-leniant parsers, AdvancedHTMLParser will by default include a space prior to the close-tag '>' character in HTML output.
418+
419+
For example:
420+
421+
<span id="abc" >Blah</span>
422+
423+
<br />
424+
425+
<hr class="bigline" />
426+
427+
428+
It is recommended to keep these extra spaces, but if for some reason you feel you need to get rid of them, you can use either *AdvancedHTMLSlimTagFormatter* or *AdvancedHTMLSlimTagMiniFormatter*.
429+
430+
431+
*AdvancedHTMLSlimTagFormatter* will do pretty-printing (like getFormattedHTML / AdvancedHTMLFormatter.getHTML output)
432+
433+
*AdvancedHTMLSlimTagMiniFormatter* will do mini-printing (like getMiniHTML / AdvancedHTMLMiniFormatter.getHTML output)
434+
435+
436+
Feeding in your HTML via formatter.parseStr(htmlStr) [where htmlStr can be parser.getHTML()] will cause it to be output without the start-tag padding.
437+
438+
For example:
439+
440+
<span id="abc">Blah</span>
441+
442+
By default, self-closing tags will retain their padding so that an xhtml-compliant parser doesn't treat "/" as either an attribute or part of the attribute-value of the preceding attribute.
443+
444+
For example:
445+
446+
<hr class="bigline"/>
447+
448+
Could be interpreted as a horizontal rule with a class name of "bigline/". Most modern browsers work around this and will not have issue, but some parsers will.
449+
450+
You may pass an optional keyword-argument to the formatter constructor, slimSelfClosing=True, in order to force removal of this padding from self-closing tags.
451+
452+
For example:
453+
454+
myHtml = '<hr class="bigline" />'
455+
456+
formatter = AdvancedHTMLSlimTagMiniFormatter(slimSelfClosing=True)
457+
458+
formatter.parseStr(myHtml)
459+
460+
miniHtml = formatter.getHTML()
461+
462+
# miniHtml will now contain '<hr class="bigline"/>'
463+
464+
.
465+
415466
**formatHTML script**
416467

417468

README.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,57 @@ Use this when pretty-printing doesn't matter and you'd like to save space.
430430
You can access this same formatting off an AdvancedHTMLParser.AdvancedHTMLParser (or IndexedAdvancedHTMLParser) by calling .getMiniHTML()
431431

432432

433+
**AdvancedHTMLSlimTagFormatter and AdvancedHTMLSlimTagMiniFormatter**
434+
435+
In order to support some less-leniant parsers, AdvancedHTMLParser will by default include a space prior to the close-tag '>' character in HTML output.
436+
437+
For example:
438+
439+
<span id="abc" >Blah</span>
440+
441+
<br />
442+
443+
<hr class="bigline" />
444+
445+
446+
It is recommended to keep these extra spaces, but if for some reason you feel you need to get rid of them, you can use either *AdvancedHTMLSlimTagFormatter* or *AdvancedHTMLSlimTagMiniFormatter*.
447+
448+
449+
*AdvancedHTMLSlimTagFormatter* will do pretty-printing (like getFormattedHTML / AdvancedHTMLFormatter.getHTML output)
450+
451+
*AdvancedHTMLSlimTagMiniFormatter* will do mini-printing (like getMiniHTML / AdvancedHTMLMiniFormatter.getHTML output)
452+
453+
454+
Feeding in your HTML via formatter.parseStr(htmlStr) [where htmlStr can be parser.getHTML()] will cause it to be output without the start-tag padding.
455+
456+
For example:
457+
458+
<span id="abc">Blah</span>
459+
460+
By default, self-closing tags will retain their padding so that an xhtml-compliant parser doesn't treat "/" as either an attribute or part of the attribute-value of the preceding attribute.
461+
462+
For example:
463+
464+
<hr class="bigline"/>
465+
466+
Could be interpreted as a horizontal rule with a class name of "bigline/". Most modern browsers work around this and will not have issue, but some parsers will.
467+
468+
You may pass an optional keyword-argument to the formatter constructor, slimSelfClosing=True, in order to force removal of this padding from self-closing tags.
469+
470+
For example:
471+
472+
myHtml = '<hr class="bigline" />'
473+
474+
formatter = AdvancedHTMLSlimTagMiniFormatter(slimSelfClosing=True)
475+
476+
formatter.parseStr(myHtml)
477+
478+
miniHtml = formatter.getHTML()
479+
480+
# miniHtml will now contain '<hr class="bigline"/>'
481+
482+
.
483+
433484
**formatHTML script**
434485

435486

0 commit comments

Comments
 (0)