| Line | |
|---|
| 1 | ===== |
|---|
| 2 | utils |
|---|
| 3 | ===== |
|---|
| 4 | |
|---|
| 5 | Contains helpers to perform site generation. |
|---|
| 6 | |
|---|
| 7 | reST2Web |
|---|
| 8 | ======== |
|---|
| 9 | |
|---|
| 10 | The rest2Web function takes a reST file and returns |
|---|
| 11 | a 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 | |
|---|
| 25 | extractHtmlContent |
|---|
| 26 | ================== |
|---|
| 27 | |
|---|
| 28 | This function is used to extract the title and the body |
|---|
| 29 | from 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 | |
|---|
| 44 | Let'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 | |
|---|