root / pycommunity / pycommunity / doc / utils.txt

Revision 68:83208f451b91, 1.1 kB (checked in by Tarek Ziad?? <tarek@…>, 21 months ago)

moving around

Line 
1=====
2utils
3=====
4
5Contains helpers to perform site generation.
6
7reST2Web
8========
9
10The rest2Web function takes a reST file and returns
11a cleaned html content, using `docutils` tools::
12
13    >>> from utils import rest2Web
14    >>> title, body = rest2Web('tests/svn/project/recipes/glossary_recipe.txt')
15    >>> title
16    'How to make a glossary'
17    >>> print body
18    <div class="document" id="how-to-make-a-glossary">
19    ...
20    word: definition
21    word2: definition
22    ...
23    </div>
24
25extractHtmlContent
26==================
27
28This function is used to extract the title and the body
29from a reST-generated html file. Let's write such a file::
30
31    >>> web_page = """\
32    ... <html>
33    ...   <header>
34    ...     <title>%s</title> 
35    ...   </header>
36    ...   <body>%s</body>
37    ... </html>
38    ... """ % (title, body)
39    >>> path = 'tests/www/test.html'
40    >>> f = open(path, 'w')
41    >>> f.write(web_page)
42    >>> f.close()
43
44Let's try now if we find back the title and body::
45
46    >>> from utils import extractHtmlContent
47    >>> ex_title, ex_body = extractHtmlContent(path)
48    >>> ex_title == title, ex_body == body
49    (True, True)
50
Note: See TracBrowser for help on using the browser.