Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactor metainfo rendering - use misc.xhtml_page and therefore main …

…stylesheet
  • Loading branch information...
commit 03333db5b2bd28577853bab80a70f6565a8cba6a 1 parent 32477c2
Volker Haas authored
31  mwlib/epub/metainfo.py
@@ -5,27 +5,12 @@
5 5
 # See README.txt for additional licensing information.
6 6
 
7 7
 import re
8  
-
9  
-from xml.sax.saxutils import escape as xmlescape
10  
-
11  
-from lxml import etree
12 8
 from lxml.builder import ElementMaker
  9
+from utils.misc import xhtml_page
13 10
 
14 11
 _ = lambda txt: txt # FIXME: add proper translation support
15 12
 E = ElementMaker()
16 13
 
17  
-metainfo_skeleton = '''<?xml version="1.0" encoding="UTF-8" ?>
18  
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
19  
-<html xmlns="http://www.w3.org/1999/xhtml">
20  
-<head><title>%(title)s</title></head>
21  
-<body><h1 style="margin-top:15%%;font-size:200%%;text-align:center;">%(title)s</h1>
22  
-
23  
-%(metainfo)s
24  
-
25  
-</body>
26  
-</html>
27  
-'''
28  
-
29 14
 def _filterAnonIpEdits(authors):
30 15
     if authors:
31 16
         authors_text = ', '.join([a for a in authors if a != 'ANONIPEDITS:0'])
@@ -35,7 +20,7 @@ def _filterAnonIpEdits(authors):
35 20
     return authors_text
36 21
 
37 22
 def getArticleMetainfo(chapter, collection):
38  
-    metainfo = E.ul(style='list-style-type:none;font-size:50%')
  23
+    metainfo = E.ul({'class': 'metainfo'})
39 24
     for lvl, webpage in collection.outline.walk():
40 25
         if not hasattr(webpage, 'contributors'):
41 26
             continue
@@ -44,17 +29,16 @@ def getArticleMetainfo(chapter, collection):
44 29
                  E.i(_('Source')), ': ',
45 30
                  E.a(webpage.url, href=webpage.url), ' ',
46 31
                  E.i(_('Contributors')), ': ', contributors,
47  
-                 style='margin-bottom:1em;'
48 32
                  )
49 33
         metainfo.append(m)
50 34
 
51  
-    xml = metainfo_skeleton % dict(title=xmlescape(_(chapter.title)),
52  
-                                   metainfo=etree.tostring(metainfo))
  35
+    body_content = [E.h1(_(chapter.title)), metainfo]
  36
+    xml = xhtml_page(title=_(chapter.title), body_content=body_content)
53 37
     return xml
54 38
 
55 39
 
56 40
 def getImageMetainfo(chapter, collection):
57  
-    metainfo = E.ul(style='list-style-type:none;font-size:50%')
  41
+    metainfo = E.ul({'class': 'metainfo'})
58 42
     for img_title, info in collection.img_contributors.items():
59 43
         contributors = _filterAnonIpEdits(info['contributors'])
60 44
         m = E.li(E.b(img_title), ' ',
@@ -64,7 +48,6 @@ def getImageMetainfo(chapter, collection):
64 48
                  E.i(_('Contributors')), ': ', contributors,
65 49
                  )
66 50
         metainfo.append(m)
67  
-
68  
-    xml = metainfo_skeleton % dict(title=xmlescape(_(chapter.title)),
69  
-                                   metainfo=etree.tostring(metainfo))
  51
+    body_content = [E.h1(_(chapter.title)), metainfo]
  52
+    xml = xhtml_page(title=_(chapter.title), body_content=body_content)
70 53
     return xml
5  mwlib/epub/wp.css
@@ -377,3 +377,8 @@ div.gallerytext{
377 377
   word-wrap:break-word;
378 378
   border-top: 1px dashed #ccc;
379 379
 }
  380
+
  381
+.metainfo {
  382
+  font-size: 0.5em;
  383
+  list-style-type:none;
  384
+}

0 notes on commit 03333db

Please sign in to comment.
Something went wrong with that request. Please try again.