1
|
1 # -*- coding: utf-8 -*-
|
|
2 #
|
|
3 # Copyright (C) 2006 Christopher Lenz
|
|
4 # All rights reserved.
|
|
5 #
|
|
6 # This software is licensed as described in the file COPYING, which
|
|
7 # you should have received as part of this distribution. The terms
|
|
8 # are also available at http://trac.edgewall.com/license.html.
|
|
9 #
|
|
10 # This software consists of voluntary contributions made by many
|
|
11 # individuals. For the exact contribution history, see the revision
|
|
12 # history and logs, available at http://projects.edgewall.com/trac/.
|
|
13
|
|
14 """This package provides various means for generating and processing web markup
|
|
15 (XML or HTML).
|
|
16
|
|
17 The design is centered around the concept of streams of markup events (similar
|
|
18 in concept to SAX parsing events) which can be processed in a uniform manner
|
|
19 independently of where or how they are produced.
|
|
20
|
|
21
|
|
22 Generating content
|
|
23 ------------------
|
|
24
|
|
25 Literal XML and HTML text can be used to easily produce markup streams
|
|
26 via helper functions in the `markup.input` module:
|
|
27
|
|
28 >>> from markup.input import XML
|
|
29 >>> doc = XML('<html lang="en"><head><title>My document</title></head></html>')
|
|
30
|
|
31 This results in a `Stream` object that can be used in a number of way.
|
|
32
|
|
33 >>> doc.render(method='html', encoding='utf-8')
|
|
34 '<html lang="en"><head><title>My document</title></head></html>'
|
|
35
|
|
36 >>> from markup.input import HTML
|
|
37 >>> doc = HTML('<HTML lang=en><HEAD><TITLE>My document</HTML>')
|
|
38 >>> doc.render(method='html', encoding='utf-8')
|
|
39 '<html lang="en"><head><title>My document</title></head></html>'
|
|
40
|
|
41 >>> title = doc.select('head/title')
|
|
42 >>> title.render(method='html', encoding='utf-8')
|
|
43 '<title>My document</title>'
|
|
44
|
|
45
|
|
46 Markup streams can also be generated programmatically using the
|
|
47 `markup.builder` module:
|
|
48
|
|
49 >>> from markup.builder import tag
|
|
50 >>> doc = tag.DOC(tag.TITLE('My document'), lang='en')
|
|
51 >>> doc.generate().render(method='html')
|
|
52 '<doc lang="en"><title>My document</title></doc>'
|
|
53
|
|
54 """
|
|
55
|
|
56 from markup.core import *
|
|
57 from markup.input import XML, HTML
|