Prettify HTML5 middleware

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import tidy

options = dict(
		add_xml_decl=False,
		doctype='omit',
		indent=1,
		tidy_mark=0,
		hide_comments=False,
		wrap=100,
		new_blocklevel_tags='article,header,footer,section,nav',
		new_inline_tags='video,audio,canvas,ruby,rt,rp',
		input_xml=1,
		output_xhtml=1,
		char_encoding='utf8',
)

class PrettifyMiddleware(object):
	"""Prettify middleware"""

	def process_response(self, request, response):
		if response.__getitem__('Content-Type').split(';', 1)[0] == 'text/html':
			content = response.content
			content = str(tidy.parseString(content, **options))
			response.content = content
		return response

More like this

  1. HTML5 Placeholder from FormField label by Hillshum 1 year, 6 months ago
  2. HTML 5 Firefox 2 Hack by epicserve 4 years, 5 months ago
  3. Custom Widget Types for HTML5 Form Fields by leveillej 3 years, 11 months ago
  4. HTML5 filter for XXS by ronnie 2 years, 11 months ago
  5. Django Number Input by silent1mezzo 3 years, 2 months ago

Comments

(Forgotten your password?)