====== README ====== The util.py module provides methods for cleanup HTML content. Let's test what the method can do for us. As you can see the method only removes the html and body tags.: >>> from pprint import pprint >>> from j01.editor import util clean ----- A simple clean method call with default allowed tags looks like: >>> raw = "
Here comes content
" >>> print(util.clean(raw))
Here comes content
The method will allways convert
tags to
: >>> raw = "
Here
comes
" >>> print(util.clean(raw))
Here
comes
and bold tags will always converted to tags: >>> raw = "
Here comes content
" >>> print(util.clean(raw))
Here comes content
The Id attribute is by default allowed: >>> raw = '
Here
comes
' >>> print(util.clean(raw))
Here
comes
but any style attribute get removed: >>> raw = '
Here
comes
' >>> print(util.clean(raw))
Here
comes
Bad tags also get cleanup up: >>> raw = "
Here
" >>> print(util.clean(raw))
Here
And of corse tags get rendered with it's relevant attributes and the query arguments get escaped: >>> url = 'http://sv1.refline.ch/100000/0004/index.html?cid=&lang=' >>> link = 'link' % url >>> raw = '
%s
' % link >>> print(util.clean(raw))
link
simpleHTML ---------- We provide some cleanup methods which uses a predefined tag white list. Let's test the simeHTML method which only uses a small set of HTML tags. First check the tag white list: >>> for t in util.ALLOWED_TAGS: ... print(t) a abbr acronym b br blockquote code div em i li ol p span strong ul and our default allowed attributes >>> for k,v in sorted(util.ALLOWED_ATTRIBUTES.items()): ... print(k) ... for vitem in sorted(v): ... print(" ",vitem) a class href id name target abbr class id title acronym class id title b class id title blockquote class id title br code class id title div class id title em class id title i class id title li class id title ol class id title p class id title span class id title strong class id title ul class id title simpleHTML -
: >>> raw = "
Here
comes
" >>> print(util.simpleHTML(raw))
Here
comes
simpleHTML -

: >>> raw = "

Here

comes
" >>> print(util.simpleHTML(raw))

Here

comes
simpleHTML - : >>> raw = "
Here comes
" >>> print(util.simpleHTML(raw))
Here comes
simpleHTML - : >>> raw = "
Here comes
" >>> print(util.simpleHTML(raw))
Here comes
simpleHTML -

/
- : >>> raw = "
  - Here
  comes
  " >>> print(util.simpleHTML(raw))
  - Here
  comes
  simpleHTML -
  /
  1. : >>> raw = "
     1. Here
     comes
     " >>> print(util.simpleHTML(raw))
     1. Here
     comes
     simpleHTML -
     ->
     : >>> raw = "
     Here
     comes
     " >>> print(util.simpleHTML(raw))
     Here
     comes
     simpleHTML - -> : >>> raw = "
     Here comes content
     " >>> print(util.simpleHTML(raw))
     Here comes content
     simpleHTML - id attribute doesn't get removed: >>> raw = '
     Here
     comes
     ' >>> print(util.simpleHTML(raw))
     Here
     comes
     simpleHTML - class attribute doesn't get removed: >>> raw = '
     Here
     comes
     ' >>> print(util.simpleHTML(raw))
     Here
     comes
     simpleHTML - style attribute get removed: >>> raw = '
     Here
     comes
     ' >>> print(util.simpleHTML(raw))
     Here
     comes
     simpleHTML - href with our special cid and language marker: >>> url = 'http://sv1.refline.ch/100000/0004/index.html?cid=&lang=' >>> link = 'link' % url >>> raw = '
     %s
     ' % link >>> print(util.simpleHTML(raw))
     link